The sum of matrix elements in a specified dimension. |
||
Syntax |
S = Sum(M, DIM) |
|
Argument |
Name |
Description |
M |
A vector or a matrix. |
|
DIM (optional) |
The dimension on which to sum. For sums by column, dim = 1. For sums by row, dim = 2. If m is a matrix, dim defaults to 1. If m is a vector and dim is omitted, the sum of the elements is returned, regardless of the vector orientation. |
|
Output |
Name |
Description |
S |
The sum of the row/column vector elements. If m is matrix, s will be either a row vector or a column vector, depending on the value of dim. |
|
Example |
Find the column sums of a matrix. |
|
Syntax |
||
S = Sum([1,2;3,4], 1) |
||
Result |
||
S = [4, 6] |
||
See Also: |