Input array, specified as a vector, matrix, or multidimensional
array.

If `A`

is a scalar, then `sum(A)`

returns `A`

.

If `A`

is an empty 0-by-0 matrix,
then `sum(A)`

returns `0`

.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `logical`

| `char`

| `duration`

**Complex Number Support: **Yes

Dimension
to operate along, specified as a positive integer scalar. If no value
is specified, then the default is the first array dimension whose
size does not equal 1.

Dimension `dim`

indicates the dimension whose
length reduces to 1. The `size(S,dim)`

is `1`

,
while the sizes of all other dimensions remain the same.

Consider a two-dimensional input array, `A`

:

`sum(A,1)`

operates on successive
elements in the columns of `A`

and returns a row
vector of the sums of each column.

`sum(A,2)`

operates on successive
elements in the rows of `A`

and returns a column
vector of the sums of each row.

`sum`

returns `A`

when `dim`

is
greater than `ndims(A)`

or when `size(A,dim)`

is `1`

.

**Data Types: **`double`

| `single`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

Output data type, specified as `'default'`

, `'double'`

,
or `'native'`

. These options also specify the data
type in which the operation is performed.

`outtype` | Output data type |

`'default'` | `double` , unless the input data type is `single` or `duration` ,
in which case, the output is `'native'` |

`'double'` | `double` , unless the data type is `duration` ,
in which case, `'double'` is not supported |

`'native'` | same data type as the input, unless the input data type is `char` ,
in which case, `'native'` is not supported |

**Data Types: **`char`

`NaN`

condition, specified as one of these
values:

`'includenan'`

— Include `NaN`

values
when computing the sum, resulting in `NaN`

.

`'omitnan'`

— Ignore all `NaN`

values
in the input.

The `sum`

function does not support the `nanflag`

option
for `duration`

arrays.

**Data Types: **`char`