Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: nansum vs nanmean
Replies: 4   Last Post: Nov 27, 2012 6:09 PM

 Messages: [ Previous | Next ]
 Peter Perkins Posts: 156 Registered: 8/12/11
Re: nansum vs nanmean
Posted: Nov 27, 2012 5:02 PM

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...
>
> --

Date Subject Author
11/27/12 Young Ryu
11/27/12 dpb
11/27/12 dpb
11/27/12 Peter Perkins
11/27/12 dpb