Mean ignoring NaN values
y = nanmean(X)
y = nanmean(X,dim)
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.
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