Finding sum of a Matrix
We may use a single colon as an index into a matrix selects all the elements of the array and arranges them (in column order) into a single column vector, Like :
Example
>> A = [1,2,3; 4,5,6; 7,8,9] A = 1 2 3 4 5 6 7 8 9 >> A(:) ans = 1 4 7 2 5 8 3 6 9
Same colon used to find the sum of whole matrix as :
>> sum(A(:)) ans = 45
We may find sum of Individual columns as :
>> A = [1,2,3; 4,5,6; 7,8,9] A = 1 2 3 4 5 6 7 8 9 >> sum(A) ans = 12 15 18