MATLAB: Special sum of an array

arraysum

hi all, is there any function to do this simply:
Array=[a1 a2 .......an]
i want to calculate this:
ArraySum=[a1 a1+a2 a1+a2+a3 .......a1+a2+a3+...an]
Thank you!

Best Answer

That's a cumulative sum, cumsum is the function you want:
a = [1 2 3]
cumsum(a)
ans =
1 3 6