cumsum

Scilab Function
Last update : 02/11/2005

cumsum - cumulative sum

### Calling Sequence

  `y=cumsum(x)`
  `y=cumsum(x,'r') or y=cumsum(x,1)`
  `y=cumsum(x,'c') or y=cumsum(x,2)`

### Parameters

- `x` : vector or matrix (real or complex)
- `y` : vector or matrix (real or complex)

### Description

For a vector or a matrix `x` , `y=cumsum(x)` returns in `y` the cumulative sum of all the entries of `x` taken columnwise.

`y=cumsum(x,'c')` (or, equivalently, `y=cumsum(x,2)` ) returns in `y` the cumulative sum of the columns of `x` : `y(i,:)=cumsum(x(i,:))`

`y=cumsum(x,'r')` (or, equivalently, `y=cumsum(x,1)` ) returns in `y` the cumulative sum of the rows of `x` : `y(:,i)=cumsum(x(:,i))`

`y=cumsum(x,'m')` is the cumulative sum along the first non singleton dimension of `x` (for compatibility with Matlab).

### Examples

    A=[1,2;3,4];
    cumsum(A)
    cumsum(A,'r')
    cumsum(A,'c')
    a=rand(3,4)+%i;
    [m,n]=size(a);
    w=zeros(a);
    w(1,:)=a(1,:);
    for k=2:m;w(k,:)=w(k-1,:)+a(k,:);end;w-cumsum(a,'r')

### See Also

`cumprod` , `sum` ,