for loop to get results for each iteration

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops 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