cumsum

Syntax

cumsum(X)

Arguments

X is a vector/matrix.

Details

If X is a vector, cumulatively calculate the sum of the elements in X and return a vector of the same length as X.

If X is a matrix, perform the calculation mentioned above along each row and return a matrix of the same dimension as X.

Examples

$ x=[2,3,4];
$ cumsum(x);
[2,5,9]

$ m=matrix(1 2 3, 4 5 6);
$ m;

#0

#1

1

4

2

5

3

6

$ cumsum(m);

#0

#1

1

4

3

9

6

15

Related functions: cummax, cummin, cumprod, cumPositiveStreak, cumsum2, cumsum3