How to maintain a sum in a matrix with the movsum function

5 views (last 30 days)
Novice user here. I would like to add each row within a matrix together. Basically, I want to add the second element to the first element, add the third element to that resulting sum, etc. (for a one-column matrix).
For example: A = [1 2 3] Desired result: B = [1 3 6]
I have tried using the movsum function, but I can't seem to maintain the sums within the matrix. It adds together the initial values within the column rather than carrying the resulting sum for each row throughout the matrix.
Is movsum the wrong function?
Any help is greatly appreciated!

Accepted Answer

Walter Roberson
Walter Roberson on 22 Apr 2018
cumsum(A, 2)

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!