MATLAB: Summation of array elements

summation

I have an array of say 5 elements and I want to run a loop and find the cumulative sum till the ith iteration eg.
array if f=[1 2 3 4 5]
so in the first iteration sum should be 1,in the 2nd it should be 3,in the third it should be 6 and so on…
what is the most efficient way to do this?
thanks in advance:]

Best Answer

f=[1 2 3 4 5];
out=cumsum(f)
Related Question