- do you wish to change how the data are displayed in the command window?
- are you attempting to remove those characters from the text data itself? (note: most likely they are not part of the text data)
Suppressing braces and single quotes of a string matrix
1 Comment
Answers (4)
0 Comments
0 Comments
Hi @David Cole ,
You asked, “How do I suppress the braces and single quotes in a matrix full of strings?”
To achieve the desired output in MATLAB, you need to manipulate the cell array of strings that contains the bus voltages. The primary goal is to convert the cell array into a standard format that displays the strings without braces { } and single quotes ''. Below is a detailed explanation of how to accomplish this, along with the complete code. First, define a cell array that contains the bus voltage strings. This is the initial format we will work with. Then convert the cell array into a character array or a string array, which will allow you to manipulate the strings more easily. Finally, display the strings in a clean format, ensuring that no braces or quotes are present. Here is the complete MATLAB code that implements the above steps:
% Step 1: Define the cell array of bus voltages busVoltages = { 'V1 = 1.0120° pu'; 'V2 = 0.926752-5.7691° pu'; 'V3 = 1.0527-4.4235° pu'; 'V4 = 0.907172-3.7558° pu'; 'V5 = 1.0522-2.3978° pu'; 'V6 = 0.903952-4.0345° pu' };
% Step 2: Convert the cell array to a string array busVoltagesStr = string(busVoltages);
% Step 3: Display the strings without braces and quotes for i = 1:length(busVoltagesStr) fprintf('%s\n', busVoltagesStr(i)); end
Please see attached.
In the above code snippet, busVoltages variable is defined as a cell array containing the bus voltage strings. Each string is enclosed in single quotes and separated by semicolons. The string ( ) function is used to convert the cell array into a string array. This conversion simplifies the process of displaying the strings. A for loop iterates through each element of the string array. The fprintf function is used to print each string to the command window without any additional formatting characters. The format specifier %s ensures that only the string content is printed.
By following the steps outlined above, you can effectively suppress the braces and single quotes from a matrix of strings in MATLAB.
Hope this helps.
Please let me know if you have any further questions.
4 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!