How does one produce an array of strings automatically?
古いコメントを表示
I wish to produce an array/vector of strings to use as InputNames and OutputNames on a dynamical system model in something like the following manner (note that the below doesn't work, but illustrates what I'm looking for):
n = 5;
stringVector = {'v' num2str(n)};
in order to produce a vector of strings as such:
stringVector = {'v1', 'v2', 'v3', 'v4', 'v5'}
How can this be done?
Thanks, Olie
採用された回答
その他の回答 (2 件)
Jan
2014 年 4 月 14 日
There is an undocumented but extremely efficient function for this job:
stringVector = sprintfc('v%d', 1:5)
Sean de Wolski
2014 年 4 月 16 日
And a documented one liner:
x = strcat('v',cellstr(num2str((1:5).')))
1 件のコメント
Walter Roberson
2014 年 4 月 16 日
x = cellstr(num2str((1:5).', 'v%d'));
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!