Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Interesting INTERP1 behavior

Subject: Interesting INTERP1 behavior

From: Jordan Rosenthal

Date: 30 Jun, 2005 12:53:41

Message: 1 of 7

Hi all,

I found some interesting behavior in INTERP1:

%--------------------
 >> interp1([-inf 10 20 inf],[30 30 40 40],0:5:30)

ans =

    NaN NaN 30 35 40 40 40
%--------------------

Ideally, I would want this to produce [30 30 30 35 40 40 40]. However,
I'd probably be okay if it produced an error along the lines of "inputs
must be finite".

I reported this as a bug (albeit minor) to The Mathworks, but thought
I'd share here.

Jordan

Subject: Interesting INTERP1 behavior

From: Bob Alvarez

Date: 30 Jun, 2005 11:56:29

Message: 2 of 7

>From the documentation for interp1

'For the 'nearest', 'linear', and 'v5cubic' methods,
interp1(x,Y,xi,method) returns NaN for any element of xi that is
outside the interval spanned by x. For all other methods, interp1
performs extrapolation for out of range values.'

The default method is linear, so the behavior seems to be according to
spec

Subject: Interesting INTERP1 behavior

From: Jordan Rosenthal

Date: 30 Jun, 2005 17:52:44

Message: 3 of 7

Bob,

Actually, no, it doesn't.

If it really worked that way, then the NaNs would have appeared on
"both" sides of the interval I gave it. That is, it would have produced:

   [NaN NaN 30 35 40 NaN NaN]

instead of what I got which was:

   [NaN NaN 30 35 40 40 40]

Jordan

Bob Alvarez wrote:
>>From the documentation for interp1
>
> 'For the 'nearest', 'linear', and 'v5cubic' methods,
> interp1(x,Y,xi,method) returns NaN for any element of xi that is
> outside the interval spanned by x. For all other methods, interp1
> performs extrapolation for out of range values.'
>
> The default method is linear, so the behavior seems to be according to
> spec
>

Subject: Interesting INTERP1 behavior

From: Rajeev

Date: 30 Jun, 2005 15:50:12

Message: 4 of 7

Jordan Rosenthal wrote:
> Hi all,
>
> I found some interesting behavior in INTERP1:
>
> %--------------------
> >> interp1([-inf 10 20 inf],[30 30 40 40],0:5:30)
>
> ans =
>
> NaN NaN 30 35 40 40 40
> %--------------------
>
> Ideally, I would want this to produce [30 30 30 35 40 40 40]. However,
> I'd probably be okay if it produced an error along the lines of "inputs
> must be finite".
>
> I reported this as a bug (albeit minor) to The Mathworks, but thought
> I'd share here.
>
> Jordan

Indeed interesting. I tried and noticed that

>> interp1([-realmax 10 20 inf],[30 30 40 40],0:5:30)
ans =
    30 30 30 35 40 40 40

works fine. Let us know what TMW has to say.

Regards,
-rajeev-

Subject: Interesting INTERP1 behavior

From: Doug Schwarz

Date: 1 Jul, 2005 00:16:02

Message: 5 of 7

[top posting repaired]

In article <MQZwe.98$75.91@llslave.llan.ll.mit.edu>,
 Jordan Rosenthal <jr@ll.mit.edu> wrote:

> Bob Alvarez wrote:
> >>From the documentation for interp1
> >
> > 'For the 'nearest', 'linear', and 'v5cubic' methods,
> > interp1(x,Y,xi,method) returns NaN for any element of xi that is
> > outside the interval spanned by x. For all other methods, interp1
> > performs extrapolation for out of range values.'
> >
> > The default method is linear, so the behavior seems to be according to
> > spec
> >
> Bob,
>
> Actually, no, it doesn't.
>
> If it really worked that way, then the NaNs would have appeared on
> "both" sides of the interval I gave it. That is, it would have produced:
>
> [NaN NaN 30 35 40 NaN NaN]
>
> instead of what I got which was:
>
> [NaN NaN 30 35 40 40 40]
>
> Jordan


Hi Jordan (we haven't communicated in quite a while)!

Actually, there are no points outside the x interval since the minimum x
is -inf and the maximum x is +inf and every number I can think of is
between those two extremes. :-)

I say that your example should work and indeed, when you replace inf
with realmax it does work -- at least in the ancient version 5.2 that I
have.

--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.

Subject: Interesting INTERP1 behavior

From: Jordan Rosenthal

Date: 1 Jul, 2005 07:54:22

Message: 6 of 7

Hi Doug,

Yep, your right; I screwed up that last post.

The Mathworks did reply to my bug submission. They thanked me for my
suggestions to improve the INTERP1 function, and suggested a few
alternatives.

Jordan

PS I don't get to read the group as regularly as I used to. Now, I'm
mostly relegated to browsing every once and a while. Ah...I miss the
days of being a graduate student. :)

Doug Schwarz wrote:

> [top posting repaired]
>
> In article <MQZwe.98$75.91@llslave.llan.ll.mit.edu>,
> Jordan Rosenthal <jr@ll.mit.edu> wrote:
>
>
>>Bob Alvarez wrote:
>>
>>>>From the documentation for interp1
>>>
>>>'For the 'nearest', 'linear', and 'v5cubic' methods,
>>>interp1(x,Y,xi,method) returns NaN for any element of xi that is
>>>outside the interval spanned by x. For all other methods, interp1
>>>performs extrapolation for out of range values.'
>>>
>>>The default method is linear, so the behavior seems to be according to
>>>spec
>>>
>>
>>Bob,
>>
>>Actually, no, it doesn't.
>>
>>If it really worked that way, then the NaNs would have appeared on
>>"both" sides of the interval I gave it. That is, it would have produced:
>>
>> [NaN NaN 30 35 40 NaN NaN]
>>
>>instead of what I got which was:
>>
>> [NaN NaN 30 35 40 40 40]
>>
>>Jordan
>
>
>
> Hi Jordan (we haven't communicated in quite a while)!
>
> Actually, there are no points outside the x interval since the minimum x
> is -inf and the maximum x is +inf and every number I can think of is
> between those two extremes. :-)
>
> I say that your example should work and indeed, when you replace inf
> with realmax it does work -- at least in the ancient version 5.2 that I
> have.
>

Subject: Interesting INTERP1 behavior

From: Doug Schwarz

Date: 1 Jul, 2005 17:24:57

Message: 7 of 7

In article <O9axe.99$75.84@llslave.llan.ll.mit.edu>,
 Jordan Rosenthal <jr@ll.mit.edu> wrote:

> Ah...I miss the days of being a graduate student. :)

But not the paycheck, I'll bet!

--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us