nanmean different outcomes?

2 次查看(过去 30 天)
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?

采纳的回答

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

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by