How do I specify the cell array to indicate strings in double quotation?

I have an array of strings (pulled from Excel column headers).
For example,
A{1,1} = 'Station Number'
A{1,2} = 'Depth'
etc.
How do I specify the array, so that the output is (please note the double quotation)'
"Station Number"
"Depth"
etc.
The reason I want double quotation is to use the newline function.
Thank you.

 Accepted Answer

Use the string (link) function:
A{1,1} = 'Station Number'
A{1,2} = 'Depth'
A = string(A)
producing:
A =
1×2 cell array
{'Station Number'} {'Depth'}
A =
1×2 string array
"Station Number" "Depth"
So ‘A’ begins as a cell array and after the conversion becomes a string array.
Is that what you want to do?

7 Comments

Exactly what I want! Thank you very much.
Can you help me find the bug of my code?
AA = [];
for i = 1:length(E)
AA = [AA +newline+ string(B{1,E(i)}) ];
end
app.text.Value = AA;
There are some extra preceding 10s in the final results. What is causing this?
10Temp_1_Flag
10Temp_2
10Temp_2_Flag
10Sal_2
10Sal_2_Flag
It should be like this:
Temp_1_Flag
Temp_2
Temp_2_Flag
Sal_2
Sal_2_Flag
I don’t have enough information.
What are ‘AA’, ‘B’, and ‘E’? (I need to test your code to see if I can find out what’s wrong. I only need a few values, not the entire array.)
EDIT —
I can’t run your code without your data to test it with. However the spacing in the vector is likely an issue.
Try this instead:
AA = [AA + newline + string(B{1,E(i)}) ];
Also see if the compose (link) function will do what you want. You might be able to avoid the loop entirely.
Experiment to get the result you want.
Thank you!
Attached is my Excel file example.
[A, B, C] = xlsread (example.xlsx);
B = B(1,:);
E = [1;2;3];
AA = [];
for i = 1:length(E)
AA = [AA +newline+ string(B{1,E(i)}) ];
end
app.text.Value = AA;
I'm writing the code under Matlab app designer, BTW.
After changing it to the below, it is working perfectly now. I really appreciate your help!
AA = [AA newline B{1,E(i)}];

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

on 12 Apr 2019

Commented:

on 12 Apr 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!