필터 지우기
필터 지우기

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

조회 수: 2 (최근 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 CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by