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
X
is a vector, thennanmean(X)
is the mean of all the non-NaN
elements ofX
.If
X
is a matrix, thennanmean(X)
is a row vector of column means, computed after removingNaN
values.If
X
is a multidimensional array, thennanmean
operates along the first nonsingleton dimension ofX
. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same.nanmean
removes allNaN
values.
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
nanmean
computes the mean of an array of allNaN
values, the array is empty once theNaN
values are removed and, therefore, the sum of the remaining elements is0
. Because the mean calculation involves division by0
, the mean value isNaN
. The outputNaN
is not a mean ofNaN
values.