Sum
Sum of array elements
Syntax
sum(x) |
x is a scalar or matrix |
If x is a row or column vector, sum(x) return the sum of all elements. If x is a matrix, sum(x) treats the columns of x as vectors, returning a row vector of the sums of each column. |
sum(x, n) |
x is a matrix, n is either 1 or 2 |
sum(x,n) sums along the dimension of x specified by scalar dim. Set n to 1 to compute the sum of each column, 2 to sum rows. |
Examples
Input |
Output |
sum([1, 2, 3, 4]) |
|
sum([1, 3, 4; 2, 4, 6]) |
|
sum([1, 3, 4; 2, 4, 6], 1) |
|
sum([1, 3, 4; 2, 4, 6], 2) |
See Also
Created with the Personal Edition of HelpNDoc: Full-featured EBook editor