Alternatives to nanmean?

27 次查看(过去 30 天)
ZH
ZH 2020-7-18
How could I create a mean funtion that ignores NaN values?
I am trying to find the average of a column even with “NaN” values and nanmean requies extra downloads.

回答(1 个)

KSSV
KSSV 2020-7-18
Let A be your array which have NaN's.
% Remove the nan's first
A(isnan(A)) = [] ;
themean = mean(A) ;
Also read about mean function, it has an option to omitnans.
  1 个评论
Walter Roberson
Walter Roberson 2020-7-18
The mean() 'omitnan' option is what I would recommend these days, provided that your MATLAB is new enough to have it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by