cumsum
Cumulative sum
Description
returns the
cumulative sum of B
= cumsum(A
)A
starting at the beginning of the first array
dimension in A
whose size does not equal 1.
If
A
is a vector, thenB
is a vector of the same size containing the cumulative sum ofA
.If
A
is a matrix, thenB
is a matrix of the same size containing the cumulative sum in each column ofA
.If
A
is a multidimensional array, thenB
is an array of the same size containing the cumulative sum along the first array dimension ofA
whose size does not equal 1.If
A
is a table or timetable, thenM
is a table or timetable of the same size containing the cumulative sum in each variable ofA
. (since R2023a)
The class of B
is the same as the class of A
except if A
is logical
, in which case
B
is double
.
specifies the direction for any of the previous syntaxes. For example,
B
= cumsum(___,direction
)cumsum(A,2,"reverse")
returns the cumulative sum within the
rows of A
by working from end to beginning of the second
dimension.
Examples
Input Arguments
Tips
The
"reverse"
option in many cumulative functions allows quick directional calculations without requiring a flip or reflection of the input array.