The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Peter Perkins

Posts: 156
Registered: 8/12/11
Re: nansum vs nanmean
Posted: Nov 27, 2012 5:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.