Looping through a 3D matrix

7 vues (au cours des 30 derniers jours)
Damith
Damith le 3 Juin 2014
Réponse apportée : Narfi le 4 Juin 2014
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(:);

Réponses (1)

Narfi
Narfi le 4 Juin 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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by