Statistics: mean

### Function Reference: `mean`

statistics: m = mean (x)
statistics: m = mean (x, "all")
statistics: m = mean (x, dim)
statistics: m = mean (x, vecdim)
statistics: m = mean (…, outtype)
statistics: m = mean (…, nanflag)

Compute the mean of the elements of x.

- If x is a vector, then `mean(x)` returns the mean of the elements in x defined as $$ {\rm mean}(x) = \bar{x} = {1\over N} \sum_{i=1}^N x_i $$ where N is the length of the x vector.
- If x is a matrix, then `mean(x)` returns a row vector with the mean of each columns in x.
- If x is a multidimensional array, then `mean(x)` operates along the first nonsingleton dimension of x.

`mean (x, dim)` returns the mean along the operating dimension dim of x. For dim greater than `ndims (x)`, then m = x.

`mean (x, vecdim)` returns the mean over the dimensions specified in the vector vecdim. For example, if x is a 2-by-3-by-4 array, then `mean (x, [1 2])` returns a 1-by-1-by-4 array. Each element of the output array is the mean of the elements on the corresponding page of x. If vecdim indexes all dimensions of x, then it is equivalent to `mean (x, "all")`. Any dimension in vecdim greater than `ndims (x)` is ignored.

`mean (x, "all")` returns the mean of all the elements in x. The optional flag "all" cannot be used together with dim or vecdim input arguments.

`mean (…, outtype)` returns the mean with a specified data type, using any of the input arguments in the previous syntaxes. outtype can take the following values:

- "default" Output is of type double, unless the input is single in which case the output is of type single.
- "double" Output is of type double.
- "native". Output is of the same type as the input (`class (x)`), unless the input is logical in which case the output is of type double or a character array in which case an error is produced.

`mean (…, nanflag)` specifies whether to exclude NaN values from the calculation, using any of the input argument combinations in previous syntaxes. By default, NaN values are included in the calculation (nanflag has the value "includenan"). To exclude NaN values, set the value of nanflag to "omitnan".

See also: trimmean, median, mad, mode

Source Code: mean