# nanmean different outcomes?

4 Ansichten (letzte 30 Tage)
JamJan am 15 Mär. 2019
Kommentiert: JamJan am 15 Mär. 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?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Alex Mcaulley am 15 Mär. 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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
JamJan am 15 Mär. 2019
Thank you, indeed very logical!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu NaNs finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by