sum

Sums up the elements within the input A, along the dimension d (if d is given).

Syntax

R = sum(A)

R = sum(A,dim)

Inputs

A
The argument to be summed.
Type: double | integer | logical | struct | cell
Dimension: scalar | vector | matrix
dim
The dimension on which to sum.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar

Outputs

R
The sum of elements for each vector.

Examples

Vector:

R = sum([1,2,3])
R = 6

Matrix with a specified dimension:

R = sum([1,2,3; 4 5 6],2)
R = [Matrix] 2 x 1
 6
15