Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Tiago Dias
Tiago Dias am 17 Okt. 2018
Kommentiert: Jan am 17 Okt. 2018
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 Kommentar
Adam
Adam am 17 Okt. 2018
Variable = arrayfun( @(x) ['X', num2str( x )], 1:43, 'UniformOutput', false )
would create them all upfront.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 17 Okt. 2018
Len = 43;
V = sprintfc('X%d', 1:Len);
Or with modern Matlab versions:
V = compose('X%d', 1:Len);
Then:
title(V{i})

Weitere Antworten (1)

KSSV
KSSV am 17 Okt. 2018
for i = 1:10
plot(rand(1,10))
title(sprintf('X%d',i))
drawnow
pause(0.5)
end
  1 Kommentar
Jan
Jan am 17 Okt. 2018
+1: There is no need to store the names in an array, if you can create them dynamically.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by