How does one produce an array of strings automatically?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Mischa Kim
2014-4-14
编辑:Mischa Kim
2014-4-14
Oliver, you could do
n = 5;
for ii = 1:n
stringVector{ii} = strcat('v',int2str(ii));
end
or simply
stringVector = strcat({'v'},int2str((1:5)'));
3 个评论
更多回答(2 个)
Jan
2014-4-14
There is an undocumented but extremely efficient function for this job:
stringVector = sprintfc('v%d', 1:5)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!