What is the difference between mean(A,'omitnan') and nanmean(A) ?

조회 수: 334 (최근 30일)
LeChat
LeChat 2018년 3월 19일
댓글: Nathan Williamson 2020년 5월 2일
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!

채택된 답변

Stephen23
Stephen23 2018년 3월 19일
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
LeChat
LeChat 2018년 3월 19일
ok. It is the feeling I had. Thanks a lot!
Nathan Williamson
Nathan Williamson 2020년 5월 2일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 3월 19일
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.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by