help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sumskipnan(nan) = 0 ?


From: James Sherman Jr.
Subject: Re: sumskipnan(nan) = 0 ?
Date: Mon, 10 Sep 2007 11:17:44 -0400

> This holds if sum and sumskipnan operate on sets. But that is just not useful
> assumption for the nan-toolbox which deals with missing value problems. Take, 
> for
> example, the problem of transforming hourly to daily precipitation sums. For a
> day with no reported hourly values sumskipnan in its current form would 
> deliver
> zero precipitation, which is not exactly what one expects.

Specifically, I was thinking of vectors being sets of numbers.

Is all NaNs the only time this is a problem?  If you just want to
return NaN in this case, then you can simply check for all nan's
beforehand using the isnan function.  You can simply write your own
sum function to behave this way, something like

function y = mysumskipnan(x)

nanIndices = isnan(x);

if sum(nanIndices) == length(x),
   y = NaN;
else
   y = sum(x(~nanIndices));
end

return


reply via email to

[Prev in Thread] Current Thread [Next in Thread]