[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: handling NaN
From: |
Paul Kienzle |
Subject: |
Re: handling NaN |
Date: |
Wed, 31 Jul 2002 09:15:47 -0400 |
Or you can use nanmax as defined in octave-forge (http://octave.sf.net),
which does the same thing:
## [v, idx] = nanmax(X [, dim]);
## nanmax is identical to the max function except that NaN values are
## treated as -Inf, and so are ignored. If all values in a column are
## NaN, the maximum is returned as NaN.
##
## See also: nansum, nanmin, nanmean, nanmedian
function [v, idx] = nanmax (X, ...)
if nargin < 1
usage ("[v, idx] = nanmax(X [, dim])");
else
nanvals = isnan(X);
X(nanvals) = -Inf;
[v,idx] = max (X, all_va_args);
v(all(nanvals, all_va_args)) = NaN;
endif
endfunction
Paul Kienzle
address@hidden
On Tue, Jul 30, 2002 at 06:16:51PM -0500, Thomas S. Shores wrote:
> Heber Farnsworth wrote:
>
> > I'm have trouble with NaN values. I don't mind that they come up
> > occasionally but I need to know how to get rid of them. I'm evaluating
> > a function at various points and I need to pick the maximum point.
> > Occasionally the point will be an illegal one and it's difficult to
> > predict when that will happen. Obviously I don't want that point.
> > However the following behavior of octave makes it difficult to get the
> > point I do want.
> >
> > $ octave -q
> > octave:1> f = [1 2 3 NaN]
> > f =
> >
> > 1 2 3 NaN
> >
> > octave:2> max(f)
> > ans = NaN
> > octave:3> min(f)
> > ans = NaN
> > octave:4>
> >
> > If NaN is both the min and max of any vector it is contained in then how
> > do I get octave to return the value I want (3 in this case)?
> >
> > Heber
> >
> > -------------------------------------------------------------
> > Octave is freely available under the terms of the GNU GPL.
> >
> > Octave's home on the web: http://www.octave.org
> > How to fund new projects: http://www.octave.org/funding.html
> > Subscription information: http://www.octave.org/archive.html
> > -------------------------------------------------------------
>
> Try removing the NaNs first, e.g.,
>
> f = [1 2 3 NaN]
> max(f(!isnan(f)))
> min(f(!isnan(f)))
>
> Hope this helps
>
> Tom Shores
>
>
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
>
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------