How to create an array with the same letter but different number

1 回表示 (過去 30 日間)
Tiago Dias
Tiago Dias 2018 年 10 月 17 日
コメント済み: Jan 2018 年 10 月 17 日
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
Adam 2018 年 10 月 17 日
Variable = arrayfun( @(x) ['X', num2str( x )], 1:43, 'UniformOutput', false )
would create them all upfront.

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

採用された回答

Jan
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})

その他の回答 (1 件)

KSSV
KSSV 2018 年 10 月 17 日
for i = 1:10
plot(rand(1,10))
title(sprintf('X%d',i))
drawnow
pause(0.5)
end
  1 件のコメント
Jan
Jan 2018 年 10 月 17 日
+1: There is no need to store the names in an array, if you can create them dynamically.

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

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by