MATLAB: Sum inside a for loob

for loopsumsummationtotalwhile loop

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

Best Answer

b = 0;
for k = 1:5
a = price1 * k;
b = b + sum(a); % Or b = b + a?
end