Borrar filtros
Borrar filtros

for loop to get results for each iteration

1 visualización (últimos 30 días)
Oscar Utomo
Oscar Utomo el 17 de Jun. de 2019
Respondida: Star Strider el 17 de Jun. de 2019
I'm trying to figure out how to get my for loop to get values for each iteration I'm running but it's only giving me the results for the final iteration (column six). What should I do?
Eedmat=[10 11 12 13 14 15]
Eh2dmat=[5 6 7 8 9 10]
Eheatdmat=[4 5 6 7 8 9]
for n=1:6
Eed=Eedmat(n)
Eh2d=Eh2dmat(n)
Eheatd=Eheatdmat(n)
end
Etotal=Eed+Eh2d+Eheatd
M(:,1)=Eetot
M(:,2)
%.....
%.....
%..... Continue..
%.....
M(:,6)=Eetot

Respuestas (1)

Star Strider
Star Strider el 17 de Jun. de 2019
Your loop is not doing anything except copying your original vectors to new vectors.
Try something like this instead:
Eedmat=[10 11 12 13 14 15];
Eh2dmat=[5 6 7 8 9 10];
Eheatdmat=[4 5 6 7 8 9];
Emtx = [Eedmat; Eh2dmat; Eheatdmat]; % Vertically Concatenate
Etotal = sum(Emtx);
M = Etotal;
Even then, ‘M’ is a copy of ‘Etotal’.

Categorías

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

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by