All true, but the original post was about why nansum([NaN NaN NaN]') is zero while nanmean([NaN NaN NaN]') is NaN. The answer is, "because 0/0 equals NaN". The zero in the numerator is from nansum, the one in the denominator is from having zero things to sum up.
On 11/27/2012 10:16 AM, dpb wrote: > On 11/27/2012 9:00 AM, dpb wrote: >> On 11/27/2012 8:51 AM, Young wrote: >>> I found nanmean and nansum differ in treating NaN. Please see below. >>> Could you explain why nansum([NaN NaN NaN]') equals zero, not NaN? >> ... >> >> Behavior as documented... >> >> doc nanmean > > While it is as documented, one _might_ wonder if nansum(NaN) ought not > to return  rather than 0. But, of course, it is consistent w/ > long-term behavior of Matlab in that sum()=0 as well. Simply means > one can't tell by the result of the function that the input was empty > but if important to know need isempty() first. > > Probably a behavior that can't change for compatibility reasons... > > --