Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.2 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Elementary Functions > Matrix operations > cumsum

cumsum

cumulative sum of array elements

Syntax

y=cumsum(x)
y=cumsum(x,orientation)
y=cumsum(x,outtype)
y=cumsum(x,orientation,outtype)

Arguments

x

an array of reals, complex, booleans, polynomials or rational fractions.

orientation

This argument can be

  • either a string with possible values "*", "r", "c" or "m"

  • or a number with positive integer value

outtype

a string with possible values "native" or "double".

y

scalar or array

Description

Returns the cumulative sum of array elements. For an array x, y=cumsum(x) a matrix y of the same size as x. The value y(i) is the sum of all elements of x(1:i) i.e.:

y(i) = \sum_{k=1}^i x(k)

y=cumsum(x,orientation) returns in y the cumulative sum of x along the dimension given by orientation:

  • if orientation is equal to 1 or "r" then:

    y(\mathbf{l},j) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j)

    or

    y(\mathbf{l},j,k,\ldots) = \sum_{\mathbf{i}=1}^l x(\mathbf{i},j,k,\ldots)

  • if orientation is equal to 2 or "c" then:

    y(i,\mathbf{l}) = \sum_{\mathbf{j}=1}^l x(i,{\mathbf{j})

    or

    y(i,\mathbf{l},k,\ldots) = \sum_{\mathbf{j}=1}^l x(i,\mathbf{j},k,\ldots)

  • if orientation is equal to n then:

    y(i_1,\ldots,i_{n-1},\mathbf{l},i_{n+1},\ldots) = \sum_{\mathbf{i_n}=1}^l x(i_1,\ldots,i_{n-1},\mathbf{i_n},i_{n+1},\ldots)

  • y=cumsum(x,"*") is equivalent to y=cumsum(x)

  • y=cumsum(x,"m") is equivalent to y=cumsum(x,orientation) where orientation is the index of the first dimension of x that is greater than 1. This option is used for Matlab compatibility.

The outtype argument rules the way the summation is done:

  • For arrays of floats, of polynomials, of rational fractions, the evaluation is always done using floating points computations. The "double" or "native" options are equivalent.

  • For arrays of integers,

    if outtype="native" the evaluation is done using integer computations (modulo 2^b, where b is the number of bits used),

    if outtype="double" the evaluation is done using floating point computations.

    The default value is outtype="native".

  • For arrays of booleans,

    if outtype="native" the evaluation is done using boolean computations ( + is replaced by |),

    if outtype="double" the evaluation is done using floating point computations (%t values are replaced by 1 and %f values by 0).

    The default value is outtype="double".

This function applies, with identical rules to sparse matrices.

Examples

A=[1,2;3,4];
cumsum(A)
cumsum(A,1)

I=uint8([2 95 103;254 9 0])
cumsum(I) //native evaluation
cumsum(I,"double")
cumsum(I,2,"double")

s=poly(0,"s");
P=[s,%i+s;s^2,1];
cumsum(P),
cumsum(P,2)

B=[%t %t %f %f];
cumsum(B) //evaluation in float
cumsum(B,"native") //similar to or(B)

See also

  • sum — sum of array elements
  • cumprod — cumulative product of array elements
Report an issue
<< cumprod Matrix operations kron >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 14:57:12 CET 2019