Function Reference: mad

statistics: m = mad (x)
statistics: m = mad (x, flag)
statistics: m = mad (x, flag, "all")
statistics: m = mad (x, flag, dim)
statistics: m = mad (x, flag, vecdim)

Compute the mean or median absolute deviation (MAD).

mad (x) returns the mean absolute deviation of the values in x. mad treats NaNs as missing values and removes them.

  • If x is a vector, then mad returns the mean or median absolute deviation of the values in X.
  • If x is a matrix, then mad returns the mean or median absolute deviation of each column of X.
  • If x is an multidimensional array, then mad (x) operates along the first non-singleton dimension of x.

mad (x, flag) specifies whether to compute the mean absolute deviation (flag = 0, the default) or the median absolute deviation (flag = 1). Passing an empty variable, defaults to 0.

mad (x, flag, "all") returns the MAD of all the elements in x.

The optional variable dim forces mad 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 MAD equal to zeros (size (x)), while non-finite elements are returned as NaNs.

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

See also: median, mean, mode

Source Code: mad