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 - Ais a vector, then- sum(A)returns the sum of the elements.
- If - Ais a matrix, then- sum(A)returns a row vector containing the sum of each column.
- If - Ais a multidimensional array, then- sum(A)operates along the first array dimension whose size does not equal 1, treating the elements as vectors. The size of- Sin this dimension becomes- 1while the sizes of all other dimensions remain the same as in- A.
- If - Ais a table or timetable, then- sum(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".


![sum(A,[1 2]) collapses the pages of a 2-by-3-by-3 array into a 1-by-1-by-3 array.](sum_vecdim.png)