How to create an array with the same letter but different number
2 次查看(过去 30 天)
显示 更早的评论
Hi,
How can I create an array or cell, something like Variable = {'X1','X2','X3',...,'X43'}? when i give for example the length = 43.
So when I do my plots, i call put the title as title (variable(i))
Thanks!
1 个评论
Adam
2018-10-17
Variable = arrayfun( @(x) ['X', num2str( x )], 1:43, 'UniformOutput', false )
would create them all upfront.
采纳的回答
Jan
2018-10-17
Len = 43;
V = sprintfc('X%d', 1:Len);
Or with modern Matlab versions:
V = compose('X%d', 1:Len);
Then:
title(V{i})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!