for loop to get results for each iteration

1 回表示 (過去 30 日間)
Oscar Utomo
Oscar Utomo 2019 年 6 月 17 日
回答済み: Star Strider 2019 年 6 月 17 日
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

回答 (1 件)

Star Strider
Star Strider 2019 年 6 月 17 日
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’.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by