create from a vector a vector of cumulative sums
2 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
More Answers (1)
Alan Stevens
on 29 May 2020
cumsum does exactly that. For example:
>> x = [1 3 5 7 9];
>> cumsum(x)
ans =
1 4 9 16 25
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!