B = cumsum(A,dim) returns
the cumulative sum of the elements along dimension dim.
For example, if A is a matrix, then cumsum(A,2) returns
the cumulative sum of each row.

B = cumsum(___,direction) optionally
specifies the direction using any of the previous syntaxes. You must
specify A, and optionally can specify dim.
For instance, cumsum(A,2,'reverse') returns the
cumulative sum within the rows of A by working
from end to beginning of the second dimension.

Dimension to operate along, specified as a positive integer
scalar. If no value is specified, the default is the first array dimension
whose size does not equal 1.

Consider a two-dimensional input array, A:

cumsum(A,1) works along the rows
of A and returns the cumulative sum of each column.

cumsum(A,2) works along the columns
of A and returns the cumulative sum of each row.

Many cumulative functions in MATLAB^{®} support the 'reverse' option.
This option allows quick directional calculations without needing
a flip or reflection of the input array.