cumPositiveStreak

Syntax

cumPositiveStreak(X)

Arguments

X is a scalar/vector/matrix.

Details

If X is a vector: for each element of X, calculate the sum of consecutive positive elements of X after the last nonpositive element to the left. It returns 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=1 0 -1 1 2 2 2 1 0 -1 0 2;

$ cumPositiveStreak x;
[1,0,0,1,3,5,7,8,0,0,0,2]

$ m=matrix(1 0 -1 1 2 2 2 1 0 -1 0 2, -1 -2 -1 0 1 3 6 7 0 -1 -2 0);
$ m;

#0

#1

1

-1

0

-2

-1

-1

1

0

2

1

2

3

2

6

1

7

0

0

-1

-1

0

-2

2

0

$ cumPositiveStreak(m);

#0

#1

1

0

0

0

0

0

1

0

3

1

5

4

7

10

8

17

0

0

0

0

0

0

2

0

relaated functions: cumsum, cummax, cummin, cumprod