Effacer les filtres
Effacer les filtres

for loop to get results for each iteration

3 vues (au cours des 30 derniers jours)
Oscar Utomo
Oscar Utomo le 17 Juin 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

Réponses (1)

Star Strider
Star Strider le 17 Juin 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’.

Catégories

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

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by