*B = sum(A,dim) sums along the dimension of A specified by scalar dim.
The dim input is an integer value from 1 to N, where N is the number of dimensions in A. Set dim to 1 to compute the sum of each column, 2 to sum rows, etc.
>> A=[1 3 5]
A =
1 3 5
>> B=sum(A)
B =
9
>>
>>
>> C=[5; 5; 8]
C =
5
5
8
>> D=sum(C)
D =
18
>> E=[1 2 3; ]
E =
1 2 3
>> F=[1 2 3; 4 5 6; 7 8 9]
F =
1 2 3
4 5 6
7 8 9
>> G=sum(F)
G =
12 15 18
>> G=sum(F,2)
G =
6
15
24
*B = cumsum(A,dim) returns the cumulative sum of the elements along the dimension of A specified by scalar dim. For example, cumsum(A,1) works along the first dimension (the columns); cumsum(A,2) works along the second dimension (the rows).
>> A=cumsum(1:6)
A =
1 3 6 10 15 21
>> D=[5 6 6; 5 8 4]
D =
5 6 6
5 8 4
>> B=cumsum(D)
B =
5 6 6
10 14 10
>> B=cumsum(D,1)
B =
5 6 6
10 14 10
>> B=cumsum(D,2)
B =
5 11 17
5 13 17