Main Content

(Not recommended) Median, ignoring `NaN`

values

`nanmedian`

is not recommended. Use the MATLAB^{®} function `median`

instead. With the `median`

function, you can specify
whether to include or omit `NaN`

values for the calculation. For more
information, see Compatibility Considerations.

`y = nanmedian(X)`

is the `median`

of `X`

, computed after removing `NaN`

values.

For vectors `x`

, `nanmedian(x)`

is the median of the
remaining elements, once `NaN`

values are removed. For matrices
`X`

, `nanmedian(X)`

is a row vector of column medians,
once `NaN`

values are removed. For multidimensional arrays
`X`

, `nanmedian`

operates along the first nonsingleton
dimension.

`y = nanmedian(X,'all')`

returns the median of all elements of
`X`

, computed after removing `NaN`

values.

`y = nanmedian(X,dim)`

takes the median along the operating dimension
`dim`

of `X`

.

`y = nanmedian(X,vecdim)`

returns the median over the dimensions
specified in the vector `vecdim`

, computed after removing
`NaN`

values. Each element of `vecdim`

represents a
dimension of the input array `X`

. The output `y`

has
length 1 in the specified operating dimensions. The other dimension lengths are the same for
`X`

and `y`

. For example, if `X`

is a
2-by-3-by-4 array, then `nanmedian(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`

.