Looping through a 3D matrix

1 visualización (últimos 30 días)
Damith
Damith el 3 de Jun. de 2014
Respondida: Narfi el 4 de Jun. de 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(:);

Respuestas (1)

Narfi
Narfi el 4 de Jun. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by