Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interp1 doesn't handle NaN

190 views
Skip to first unread message

Harry Campbell

unread,
Jul 14, 1993, 12:13:07 PM7/14/93
to
In some recent work I have done on matlab I noticed that 'interp1' (and
I imagine Interp2) give errors when the encounter NaN.

Example:

Interp(X,Y,Xi,'linear')

If the Xi vector contains a value of NaN, the we see:

??? Error using ==> table1
x0 smaller than all values in first column

Error in ==> /usr6/packages/matlab/toolbox/matlab/polyfun/interp1.m
On line 72 ==> yi = table1([x,y],xi);


It would seem more reasonable for this function to follow Matlab's policy
of being "uniform and rigorous in it's treatment of NaNs," and simply
propagate the NaN result.


A second point about 'interp1'/'interp2':

If Xi, in the example above, had contained a value greater than any
value in X, or less than any value in X, then a similar error message
results. I think it would be more benificial if these values returned
NaN as well. This way programs that call 'interp1'/'interp2' aren't
forced to doing a lot of error checking, and value correction to avoid
crashing before using these functions. It will be simpler, for programs
that don't want them, to pull NaNs out of the result vectors, than to
have to check for values that will cause errors, replace them with values
that won't cause errors (remember NaNs won't work), call the function,
and go back and fix the resultant values for the inputs that had to be
changed. Isn't this the kind of thing NaN was meant for anyway?

Finally I'd like to say that I'm happy to see that The Math Works
follows and supports this newsgroup. If other companies would pay
as much attention to newsgroups, and mailing lists about their products,
there would be many more tools that are useful, error-free, and do
what the customer needs them to do.

Harry Campbell

Tristram Scott

unread,
Jul 14, 1993, 5:53:54 PM7/14/93
to
Harry Campbell (ha...@medusa.dseg.ti.com) wrote:
> In some recent work I have done on matlab I noticed that 'interp1' (and
> I imagine Interp2) give errors when the encounter NaN.

> Example:

> Interp(X,Y,Xi,'linear')

> If the Xi vector contains a value of NaN, the we see:

> ??? Error using ==> table1
> x0 smaller than all values in first column

> Error in ==> /usr6/packages/matlab/toolbox/matlab/polyfun/interp1.m
> On line 72 ==> yi = table1([x,y],xi);


> It would seem more reasonable for this function to follow Matlab's policy
> of being "uniform and rigorous in it's treatment of NaNs," and simply
> propagate the NaN result.


> A second point about 'interp1'/'interp2':

----- stuff deleted ------

The error check in interp1 is there to keep table1 happy. Both interp1 and
table1 are straight m-files, so you can change them if you want to. I prefer
to return the function value for the smallest x value if x0 is too small and
the function value for the largest x value if x0 is too large. I just changed
the lines where it says

error('x0 larger than all values in first column')
to
y(k,:) = tab(m,2:n);
etc

To check for NaN, off the top of my head, just put in a couple of lines:
if isnan(x0(k))
y(k,:) = zeros(1,n-2+1) + NaN
else
do the other stuff
end

If you want help getting this to work, send me email

Tristram
--
| Tristram Scott, Dept of Management| E-Mail t.s...@cantua.canterbury.ac.nz |
| University of Canterbury | or bus...@cantua.canterbury.ac.nz |
| Christchurch, New Zealand | Phone +64 3 364-2661 Fax +64 3 364-2020 |

0 new messages