nanmean
(Not recommended) Mean, ignoring NaN values
nanmean is not recommended. Use the MATLAB® function mean instead. With the mean function, you can specify
whether to include or omit NaN values for the calculation. For more
information, see Version History.
Description
returns
the y = nanmean(X)mean of the elements of
X, computed after removing all NaN values.
If
Xis a vector, thennanmean(X)is the mean of all the non-NaNelements ofX.If
Xis a matrix, thennanmean(X)is a row vector of column means, computed after removingNaNvalues.If
Xis a multidimensional array, thennanmeanoperates along the first nonsingleton dimension ofX. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same.nanmeanremoves allNaNvalues.
For information on how nanmean treats arrays of all
NaN values, see Tips.
returns the mean over the dimensions specified in the vector y = nanmean(X,vecdim)vecdim.
The function computes the means after removing NaN values. For example,
if X is a matrix, then nanmean(X,[1 2]) is the mean
of all non-NaN elements of X because every element
of a matrix is contained in the array slice defined by dimensions 1 and 2.
Examples
Input Arguments
Output Arguments
Tips
When
nanmeancomputes the mean of an array of allNaNvalues, the array is empty once theNaNvalues are removed and, therefore, the sum of the remaining elements is0. Because the mean calculation involves division by0, the mean value isNaN. The outputNaNis not a mean ofNaNvalues.
