Looping through a 3D matrix

3 次查看(过去 30 天)
Damith
Damith 2014-6-3
回答: Narfi 2014-6-4
Hi,
I have this code below but I need to make one column for each from 1 to 39 by vertically catenating. The last two lines as an example shows how I did by manually calling the numbers from 1. But how can i do this in a loop.? Can anyone help me?
Jan_Daily: 31 x 10000 x 39 matrix.
StartROW=1;
EndROW=31;
for i=1:39
St_matrix(:,:,i)=eval(['ZONAL_SEleven' num2str(i)]);
end
for jj=1:39
Jan_Daily(:,:,jj)=St_matrix(StartROW:EndROW,:,jj);
end
All_St1=Jan_Daily(:,:,1);
All_Jan_1=Jan_Daily(:);

回答(1 个)

Narfi
Narfi 2014-6-4
Damith,
By including the indices in the variable names, you end up with a lot of places where you need to build up strings for evaluation and then call eval.
Have you reconsidered your need about why you need to have 39 different variables as is the recommended way of avoiding calling eval: http://www.mathworks.com/help/matlab/matlab_prog/string-evaluation.html
Best,
Narfi

类别

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