cumsum

cumsum(X) returns the cumulative sum of vector X.
If X is a matrix, the cumulative sum is calculated row by row.
cumsum(X, dim) returns the cumulative sum of X along dimension dim.

Examples

> cumsum(1:4)#

            1            3            6           10
> cumsum([1 2 2; 2 4 3; 2 2 2])#

            1            2            2
            3            6            5
            5            8            7
> cumsum([1 2 2; 2 4 3])#

            1            2            2
            3            6            5
> cumsum([1 2 2; 2 4 3],2)#

            1            3            5
            2            6            9

See also

cumprod | diff | prod | sum