Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Cumulative sum

`B = cumsum(A)`

`B = cumsum(A,dim)`

`B = cumsum(___,direction)`

`B = cumsum(___,nanflag)`

returns
the cumulative sum of `B`

= cumsum(`A`

)`A`

starting at the beginning
of the first array dimension in `A`

whose size does
not equal 1.

If

`A`

is a vector, then`cumsum(A)`

returns a vector containing the cumulative sum of the elements of`A`

.If

`A`

is a matrix, then`cumsum(A)`

returns a matrix containing the cumulative sums for each column of`A`

.If

`A`

is a multidimensional array, then`cumsum(A)`

acts along the first nonsingleton dimension.

Many cumulative functions in MATLAB

^{®}support the`'reverse'`

option. This option allows quick directional calculations without needing a flip or reflection of the input array.

Was this topic helpful?