MATLAB Answers

nanmean different outcomes?

조회 수: 1(최근 30일)
JamJan 2019년 3월 15일
댓글: JamJan 2019년 3월 15일
I'm doing some analysis on data that has the following time intervals, however when I calculate the mean on two different ways (just for sanity) I ran into the following problem.
I have two arrays:
A = [NaN 1,57031250000000 1,60156250000000 1,71093750000000 1,65234375000000 1,51367187500000 1,49804687500000 1,49414062500000 1,59179687500000 1,41015625000000];
nanmean(A) = 1.5603
B = [NaN 1,64648437500000 0,796875000000000 0,667968750000000 1,65820312500000 1,69140625000000 1,39062500000000 1,66015625000000 1,40039062500000 1,57226562500000 1,65429687500000];
nanmean(B) = 1.4139
Now I have put them behind each other in a [A B] way.
C = [A B];
nanmean(C) = 1.4832
However this mean is not the same as the mean of A and B done separately.
(1.5603 + 1.4139)/2 = 1.4871
How is this possible and why is it different? Is this because of the NaNs?

채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 3월 15일
Your two arrays don't have the same number of non nan elements (10 vs 11), then the mean is
(1.5603*sum(~isnan(A)) + 1.4139*sum(~isnan(B)))/(sum(~isnan(A))+sum(~isnan(B))) = 1.4832
  댓글 수: 1
JamJan 2019년 3월 15일
Thank you, indeed very logical!

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

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by