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.

 採用された回答

Star Strider
Star Strider 2019 年 4 月 12 日
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 件のコメント

Leon
Leon 2019 年 4 月 12 日
Exactly what I want! Thank you very much.
Star Strider
Star Strider 2019 年 4 月 12 日
As always, my pleasure!
Leon
Leon 2019 年 4 月 12 日
編集済み: Leon 2019 年 4 月 12 日
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
Star Strider
Star Strider 2019 年 4 月 12 日
編集済み: Star Strider 2019 年 4 月 12 日
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.
Leon
Leon 2019 年 4 月 12 日
編集済み: Leon 2019 年 4 月 12 日
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.
Leon
Leon 2019 年 4 月 12 日
After changing it to the below, it is working perfectly now. I really appreciate your help!
AA = [AA newline B{1,E(i)}];
Star Strider
Star Strider 2019 年 4 月 12 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

質問済み:

2019 年 4 月 12 日

コメント済み:

2019 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by