Looping through a 3D matrix
1 view (last 30 days)
Show older comments
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(:);
0 Comments
Answers (1)
Narfi
on 4 Jun 2014
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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!