MATLAB: What is the difference between mean(A,’omitnan’) and nanmean(A)

arrayMATLABmatrixmeannannanmeanomitnanvector

Hi, I have a vector A (or could be a matrix) which contains finite values as well as NaNs. I want to compute the mean value of its non-NaN elements. What is the difference between mean(A,'omitnan') and nanmean(A) ? Thank you!

Best Answer

There is no practical difference for your vector.
Personally I would use mean, because nanmean is part of the Statistics Toolbox, so using it makes your code less portable.