nanmean different outcomes?

2 vues (au cours des 30 derniers jours)
JamJan
JamJan le 15 Mar 2019
Commenté : JamJan le 15 Mar 2019
Hi,
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?

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 15 Mar 2019
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 commentaire
JamJan
JamJan le 15 Mar 2019
Thank you, indeed very logical!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by