Y = cumsum(X)
Y = cumsum(X), where X is a vector, returns a matrix containing the cumulative sum of the elements of X. If X is a matrix, Y is a matrix containing the cumulative sums over each column.
cumsum(1:5) = [1 3 6 10 15]
sum(c) Copyright 1994 by The MathWorks, Inc.