Function Reference: geomean

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

Compute the geometric mean of x.

  • If x is a vector, then geomean(x) returns the geometric mean of the elements in x defined as $$ {\rm geomean}(x) = \left( \prod_{i=1}^N x_i \right)^\frac{1}{N} = exp \left({1\over N} \sum_{i=1}^N log x_i \right) $$ where N is the length of the x vector.
  • If x is a matrix, then geomean(x) returns a row vector with the geometric mean of each columns in x.
  • If x is a multidimensional array, then geomean(x) operates along the first nonsingleton dimension of x.
  • x must not contain any negative or complex values.

geomean(x, "all") returns the geometric mean of all the elements in x. If x contains any 0, then the returned value is 0.

geomean(x, dim) returns the geometric mean along the operating dimension dim of x. Calculating the harmonic mean of any subarray containing any 0 will return 0.

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

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

See also: harmmean, mean

Source Code: geomean