How I can to rename a variable in loop for?

조회 수: 1 (최근 30일)
Paula
Paula 2014년 8월 12일
편집: Ahmet Cecen 2014년 8월 12일
t= length(tiempo);
o= 1;
mes{'enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre'};
for j = 1:12:t;
J = moist_end(:,:,1,j);
strcat('moist_',mes(o))(:,:,:,o) = J
o=o+1;
end
  댓글 수: 2
Andy L
Andy L 2014년 8월 12일
Which variable are you trying to change? And what do you want it to be?
Adam
Adam 2014년 8월 12일
You can't rename variables programatically as far as I'm aware.

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

답변 (2개)

Matt J
Matt J 2014년 8월 12일
Not sure what you're trying to do, but if you want to split J into differently named partitions, the appropriate way would be to use a structure,
for j = 1:12:t;
J = moist_end(:,:,1,j);
moistStruct.(mes{o}) = J
o=o+1;
end

Ahmet Cecen
Ahmet Cecen 2014년 8월 12일
편집: Ahmet Cecen 2014년 8월 12일
There is an ugly way to do this using the eval function. Something like:
for i=1:12:t
eval(strcat('moist_',mes(o),'(:,:,:,',num2str(o),')','=J'));
end

카테고리

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