sum inside a for loob
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hi everyone, I was wondering how to sum my calculation inside loop. here is a simple code:
%
for i=1:5
a = price1 * i;
b =sum(a)
%
so how to sum a, when i type like this it gives result (b=a) for every times. It does not add(sum) all of the results
Akzeptierte Antwort
Jan
am 23 Jul. 2013
b = 0;
for k = 1:5
a = price1 * k;
b = b + sum(a); % Or b = b + a?
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!