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

조회 수: 5 (최근 30일)
Josh Culpepper
Josh Culpepper 2018년 4월 22일
댓글: Josh Culpepper 2018년 4월 23일
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!

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 22일

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by