What is the difference between mean(A,'omitnan') and nanmean(A) ?
362 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
LeChat
am 19 Mär. 2018
Kommentiert: Nathan Williamson
am 2 Mai 2020
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!
0 Kommentare
Akzeptierte Antwort
Stephen23
am 19 Mär. 2018
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.
2 Kommentare
Nathan Williamson
am 2 Mai 2020
On a related note, in my code I found median(A,'omitnan') to run significantly faster than nanmedian(A). Not sure why. In the same code, mean(A,'omitnan') and nanmean(A) have a similar runtime.
Weitere Antworten (1)
Walter Roberson
am 19 Mär. 2018
nanmean() existed first, as part of the Statistics Toolbox.
Later 'omitnan' was added as an option to the regular mean() as part of basic MATLAB. nanmean() should now be used mostly for backwards compatibility.
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!