Skip to content

cumsum

Cumulative sum along a dimension.

B = cumsum(A)
B = cumsum(A, dim)

Returns an array of the same size as A where each element is the running sum from the start of its row/column up to that position. With no dimension argument, accumulates along the first non-singleton dimension.

cumsum([1 2 3 4]) % [1 3 6 10]
cumsum([1 2; 3 4]) % [1 2; 4 6] column cumulative sums
cumsum([1 2; 3 4], 2) % [1 3; 3 7] row cumulative sums
  • sum — Sum elements of an array.
  • cumprod — Cumulative product along a dimension.