Create an array of strings
46 ビュー (過去 30 日間)
古いコメントを表示
Viesturs Veckalns
2017 年 10 月 21 日
編集済み: Viesturs Veckalns
2017 年 10 月 21 日
I try to create an array of strings
fruit = ['apple', 'cherry']
What modifications are needed so that fruit(2) is 'cherry' not 'p'?
UPDATE
Following the two first answers to this question I created a case:
style = {'.blue', '.red'};
f1 = figure;
for theta = (0:0.1:1)*pi
for ind = 1:2
figure(f1);
plot(theta, cos(theta + pi*ind), style(ind)); hold on;
end
end
The code does not accept style(ind) as an argument. The error message is
Error using plot
Invalid first data argument
2 件のコメント
per isakson
2017 年 10 月 21 日
編集済み: per isakson
2017 年 10 月 21 日
"does not accept style(ind) as an argument" That's because it is a cell array of strings, not a character string. I guess the error message said so.
Replace
style(ind)
by
style{ind}
with curly braces.
採用された回答
per isakson
2017 年 10 月 21 日
編集済み: per isakson
2017 年 10 月 21 日
>> fruit = {'apple', 'cherry'}
fruit =
'apple' 'cherry'
with curly braces creates a cell array of strings. I use R2016a. The display format for cell arrays has been changed. And to reference one of the strings
>> fruit{2}
ans =
cherry
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!