sum
Sum of array elements
Syntax
Description
S = sum(
returns the sum of the elements of A
along the first array dimension whose size does not equal 1.A
)
If
A
is a vector, thensum(A)
returns the sum of the elements.If
A
is a matrix, thensum(A)
returns a row vector containing the sum of each column.If
A
is a multidimensional array, thensum(A)
operates along the first array dimension whose size does not equal 1, treating the elements as vectors. The size ofS
in this dimension becomes1
while the sizes of all other dimensions remain the same as inA
.If
A
is a table or timetable, thensum(A)
returns a one-row table containing the sum of each variable. (since R2023a)
S = sum(___,
returns the sum
with the specified data type, using any of the input arguments in the previous
syntaxes. outtype
)outtype
can be "default"
,
"double"
, or "native"
.