MATLAB: Create from a vector a vector of cumulative sums

cumsumMATLAB

Consider a vector
[e1, e2, e3, e4,...]
I want to create a vector
[e1, e1+e2, e1+e2+e3,...]
Is there any simpler way rather than writing a loop?

Best Answer

Read about cumsum.
A = rand(10,1) ;
iwant = cumsum(A)