How to deal with for loop

I want to ask about for loop. I have 50 matrices of Z and I want to use for loop to add them and take the average of these Z matrices.

 Respuesta aceptada

David Sanchez
David Sanchez el 14 de Mayo de 2013

0 votos

N_matrices = 50; % number of matrices
total = zeros( size(Z(1) ); % initialization of total addition
for k = 1:N_matrices % loop over all the matrices
total = total + Z(k); % update the addition
end % end the loop

Más respuestas (1)

David Sanchez
David Sanchez el 14 de Mayo de 2013

0 votos

N_matrices = 50; % number of matrices total = zeros( size(Z(1) ); % initialization of total addition for k = 1:N_matrices % loop over all the matrices total = total + Z(k); % update the addition end % end the loop

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by