Categories &

Functions List

Function Reference: mean

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

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 $$

If x is an array, then mean(x) computes the mean along the first non-singleton dimension of x.

The optional variable dim forces mean to operate over the specified dimension, which must be a positive integer-valued number. Specifying any singleton dimension in x, including any dimension exceeding ndims (x), will result in a mean equal to x.

Specifying the dimensions as vecdim, a vector of non-repeating dimensions, will return the mean over the array slice defined by vecdim. If vecdim indexes all dimensions of x, then it is equivalent to the option "all". Any dimension in vecdim greater than ndims (x) is ignored.

Specifying the dimension as "all" will force mean to operate on all elements of x, and is equivalent to mean (x(:)).

The optional input outtype specifies the data type that is returned. 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 as reported

by (class (x)), unless the input is logical in which case the output is of type double.

The optional variable nanflag specifies whether to include or exclude NaN values from the calculation using any of the previously specified input argument combinations. The default value for nanflag is "includenan" which keeps NaN values in the calculation. To exclude NaN values set the value of nanflag to "omitnan". The output will still contain NaN values if x consists of all NaN values in the operating dimension.

See also: median, mode, movmean

Source Code: mean