How i can store a results of a loop FOR (are then Matrix's) in a new Matrix?

1 visualización (últimos 30 días)
Hello guys, my code have a loop iteration FOR. That generate 13 matrix, my question is, how i can store this results of loop, each iteration, in a new matrix. Where else ahead, i'm needed to pull this matriz's of my storage matrix.
Obs* = I' have a old matrix e new matrix (this into the loop) i need storage the old matrix, in first "space" of my storage matrix and in the other rows e colums i need storage the looping results.
*Sorry for my poor english.
Ee = [-P(1) e0 -P(3) P(2)
-P(2) P(3) e0 -P(1)
-P(3) -P(2) P(1) e0];
for it=2:4:52
EeNew = [-P(it+3) P(it+2) -P(it+5) P(it+4)
-P(it+4) P(it+2) P(it+2) -P(it+3)
-P(it+5) -P(it+4) P(it+3) P(it+2)];
end
%[Ee,EeNew(:,:)] = [Ee EeNew()] (my fails)

Respuesta aceptada

Eugenio Grabovic
Eugenio Grabovic el 29 de En. de 2019
Editada: Eugenio Grabovic el 29 de En. de 2019
Ee = [-P(1) e0 -P(3) P(2)
-P(2) P(3) e0 -P(1)
-P(3) -P(2) P(1) e0];
i = 0; % adding counter index
for it=2:4:52
i = i + 1;
EeNew(1:3,1:4,i) = [-P(it+3) P(it+2) -P(it+5) P(it+4) % storing evaluated matrices along the 3rd dim.
-P(it+4) P(it+2) P(it+2) -P(it+3)
-P(it+5) -P(it+4) P(it+3) P(it+2)];
end
EeNew = EeNew(:,:); % flattening 3rd dimension to make 3x(4*k) final matrix
Not sure i completely understood you question but maybe this is what you are looking for ?
  1 comentario
Lucas Silva
Lucas Silva el 29 de En. de 2019
Is this a alternative, but i find another. Creating a function. Thanks for the helping anyway!

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 29 de En. de 2019
Ee = [-P(1) e0 -P(3) P(2)
-P(2) P(3) e0 -P(1)
-P(3) -P(2) P(1) e0];
val = 2:4:52 ;
EeNew = zeros(3,4,length(val)) ;
for i = 1:length(val)
it = val(i) ;
EeNew(:,:,i) = [-P(it+3) P(it+2) -P(it+5) P(it+4)
-P(it+4) P(it+2) P(it+2) -P(it+3)
-P(it+5) -P(it+4) P(it+3) P(it+2)];
end

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by