| Statistics Toolbox™ | ![]() |
y = nanmean(X)
y = nanmean(X,dim)
y = nanmean(X) is the mean of X, computed after removing NaN values.
For vectors x, nanmean(x) is the mean of the remaining elements, once NaN values are removed. For matrices X, nanmean(X) is a row vector of column means, once NaN values are removed. For multidimensional arrays X, nanmean operates along the first nonsingleton dimension.
y = nanmean(X,dim) takes the mean along dimension dim of X.
Note If X contains a vector of all NaN values along some dimension, the vector is empty once the NaN values are removed, so the sum of the remaining elements is 0. Since the mean involves division by 0, its value is NaN. The output NaN is not a mean of NaN values. |
Find column means for data with missing values:
X = magic(3);
X([1 6:9]) = repmat(NaN,1,5)
X =
NaN 1 NaN
3 5 NaN
4 NaN NaN
y = nanmean(X)
y =
3.5000 3.0000 NaN![]() | nanmax | nanmedian | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |