Categories &

Functions List

Function Reference: trimmean

statistics: m = trimmean (x, p)
statistics: m = trimmean (x, p, flag)
statistics: m = trimmean (…, "all")
statistics: m = trimmean (…, dim)
statistics: m = trimmean (…, dim)

Compute the trimmed mean.

The trimmed mean of x is defined as the mean of x excluding the highest and lowest k data values of x, calculated as k = n * (p / 100) / 2), where n is the sample size.

m = trimmean (x, p) returns the mean of x after removing the outliers in x defined by p percent.

  • If x is a vector, then trimmean (x, p) is the mean of all the values of x, computed after removing the outliers.
  • If x is a matrix, then trimmean (x, p) is a row vector of column means, computed after removing the outliers.
  • If x is a multidimensional array, then trimmean operates along the first nonsingleton dimension of x.

To specify the operating dimension(s) when x is a matrix or a multidimensional array, use the dim or vecdim input argument.

trimmean treats NaN values in x as missing values and removes them.

m = trimmean (x, p, flag) specifies how to trim when k, i.e. half the number of outliers, is not an integer. flag can be specified as one of the following values:

ValueDescription
"round"Round k to the nearest integer. This is the default.
"floor"Round k down to the next smaller integer.
"weighted"If k = i + f, where i is an integer and f is a fraction, compute a weighted mean with weight (1 – f) for the (i + 1)-th and (n – i)-th values, and full weight for the values between them.

m = trimmean (…, "all") returns the trimmed mean of all the values in x using any of the input argument combinations in the previous syntaxes.

m = trimmean (…, dim) returns the trimmed mean along the operating dimension dim specified as a positive integer scalar. If not specified, then the default value is the first nonsingleton dimension of x, i.e. whose size does not equal 1. If dim is greater than ndims (X) or if size (x, dim) is 1, then trimmean returns x.

m = trimmean (…, vecdim) returns the trimmed 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.

See also: mean

Source Code: trimmean