필터 지우기
필터 지우기

dynamic variables

조회 수: 37 (최근 30일)
AYAH
AYAH 2012년 2월 14일
편집: Laura Pop 2013년 10월 15일
hello every body , who know how to name variables dynamically such as X1, x2,X3,...Xn in for loop

채택된 답변

Benjamin Schwabe
Benjamin Schwabe 2012년 2월 14일
Hi AYAH,
why do you want to do this, you really might want to use a vector with X(1),X(2),...,X(10), they are dynamic in MatLab, so there is nothing to worry about this. And cases are really rare, in which you want to do what you'd like to have...
However, you can do it by using assignin, e.g. like that:
n=10;
for k=1:n
varname=['X',num2str(k)];
assignin('caller',varname,k)
end
  댓글 수: 1
AYAH
AYAH 2012년 2월 15일
Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 2월 14일
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 2월 16일
If you want X0 onward, then
X{2}= [1 2 4];
X{3}= [1 7 8 9 7];
and
for i = 0:2:10
disp(X{i+1})
end
AYAH
AYAH 2012년 2월 16일
Thanks alot

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by