nanmean different outcomes?

2 visualizaciones (últimos 30 días)
JamJan
JamJan el 15 de Mzo. de 2019
Comentada: JamJan el 15 de Mzo. de 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?

Respuesta aceptada

Alex Mcaulley
Alex Mcaulley el 15 de Mzo. de 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 comentario
JamJan
JamJan el 15 de Mzo. de 2019
Thank you, indeed very logical!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by