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:
Error using interp1 function

Subject: Error using interp1 function

From: Matt

Date: 5 Dec, 2012 15:17:08

Message: 1 of 12

Hello everybody.

After using the following function :

--------------
AAA=interp1(d, time3, 20, 'linear','extrap')
--------------

I'm getting the following error :

--------------
Error using griddedInterpolant
The point coordinates are not sequenced in strict monotonic order.
--------------

Does anybody knows why ? d and time3 are both 1x330 double elements and basically I'm trying to

I can provide more details is needed.

Thanks a lot ! :-)

Subject: Error using interp1 function

From: dpb

Date: 5 Dec, 2012 17:31:44

Message: 2 of 12

On 12/5/2012 9:17 AM, Matt wrote:
...

> AAA=interp1(d, time3, 20, 'linear','extrap')
...
> I'm getting the following error :
...
> Error using griddedInterpolant
> The point coordinates are not sequenced in strict monotonic order.
...
> Does anybody knows why ?...

Because the X input must be monotonic per

doc interp1

The message says it isn't altho it could probably be a little more
explicit as to which argument is the trouble one...

--

Subject: Error using interp1 function

From: Nasser M. Abbasi

Date: 5 Dec, 2012 17:40:51

Message: 3 of 12

On 12/5/2012 11:31 AM, dpb wrote:
> On 12/5/2012 9:17 AM, Matt wrote:
> ...
>
>> AAA=interp1(d, time3, 20, 'linear','extrap')
> ...
>> I'm getting the following error :
> ...
>> Error using griddedInterpolant
>> The point coordinates are not sequenced in strict monotonic order.
> ...
>> Does anybody knows why ?...
>
> Because the X input must be monotonic per
>
> doc interp1
>
> The message says it isn't altho it could probably be a little more
> explicit as to which argument is the trouble one...
>

I did not use interp1 before, but when I did a quick test
(unless I am doing something wrong) I do not see this:

----------------------------------
EDU>> interp1([1 2 3], [1 2 3], 20, 'linear','extrap')
     20

EDU>> interp1([1 3 2], [1 2 3], 20, 'linear','extrap')
    -15
-----------------------------------

no error. X is the first argument? In second case above it is
not monotonic increasing?

" Vq = interp1(X,V,Xq) interpolates to find Vq, the values of the
     underlying function V=F(X) at the query points Xq. X must
     be a vector of length N.
"

Matlab 2012a

--Nasser

Subject: Error using interp1 function

From: Matt

Date: 5 Dec, 2012 17:46:08

Message: 4 of 12

Thank you for your message.

Well, I do not really understand what is the problem. The "d" value is always growing, as is the "time3" value, so this shouldn't be a problem, right ?

I am a bit confused there.

Subject: Error using interp1 function

From: dpb

Date: 5 Dec, 2012 18:33:24

Message: 5 of 12

On 12/5/2012 11:40 AM, Nasser M. Abbasi wrote:
> On 12/5/2012 11:31 AM, dpb wrote:
>> On 12/5/2012 9:17 AM, Matt wrote:
>> ...
>>
>>> AAA=interp1(d, time3, 20, 'linear','extrap')
>> ...
>>> I'm getting the following error :
>> ...
>>> Error using griddedInterpolant
>>> The point coordinates are not sequenced in strict monotonic order.
>> ...
>>> Does anybody knows why ?...
>>
>> Because the X input must be monotonic per
>>
>> doc interp1
>>
>> The message says it isn't altho it could probably be a little more
>> explicit as to which argument is the trouble one...
>>
>
> I did not use interp1 before, but when I did a quick test
> (unless I am doing something wrong) I do not see this:
>
> ----------------------------------
> EDU>> interp1([1 2 3], [1 2 3], 20, 'linear','extrap')
> 20
>
> EDU>> interp1([1 3 2], [1 2 3], 20, 'linear','extrap')
> -15
> -----------------------------------
>
> no error. X is the first argument? In second case above it is
> not monotonic increasing?
>
> " Vq = interp1(X,V,Xq) interpolates to find Vq, the values of the
> underlying function V=F(X) at the query points Xq. X must
> be a vector of length N.
> "
...

I see it isn't in doc's (I thought it was)...but, do you really get what
you think you should?

 >> interp1([1 3 2], [0 1 2], 1.5)
ans =
      1
 >>

Note it runs off the end even though there's a point on interval [1,3]
that should return a value of 0.25.

 >> interp1([1 3 2], [0 1 2], 2.5)
ans =
     1.5000

Here I there are two possible actual values on the intervals [1,3] and
[3,2] and it returned the latter one (1.5)

It's certainly outside the realm of reasonableness to use it w/ a
multi-valued interpolant and I don't follow why that isn't made explicit
in the documentation. I swore we had gone round this mulberry bush here
not so very long ago...

--

Subject: Error using interp1 function

From: dpb

Date: 5 Dec, 2012 18:37:53

Message: 6 of 12

On 12/5/2012 11:46 AM, Matt wrote:
> Thank you for your message.
>
> Well, I do not really understand what is the problem. The "d" value is
> always growing, as is the "time3" value, so this shouldn't be a problem,
> right ?

Show the input vectors and line that creates the problem if it's not too
long or try a subset that isn't that brackets the XI and hopefully that
will cause same symptom w/o being excessively long.

Nasser points out that the proscription I was thinking was in the doc
isn't actually there; but it doesn't make any sense to try to
interpolate when the x variable axis is multi-valued--what _should_ you
get for

interp1([0 3 2],[0 1 2],2.5)

???

--

Subject: Error using interp1 function

From: Matt

Date: 5 Dec, 2012 18:44:08

Message: 7 of 12

Thanks a lot for the help !

Well, in fact my 2 sets of results are :

- d starts from 0 and goes up to 1517 (not linear growing but still always growing)
- time3 starts from 0 and goes up to 29.9 (growing linear)

I can plot this set of results without any problem and I can spot for example that at time3=20, d=800. But when I'm trying to use the function :

-------------------
AAA=interp1(d, time3, 200, 'linear','extrap')
-------------------

It doesn't want to calculate it.

Subject: Error using interp1 function

From: dpb

Date: 5 Dec, 2012 19:23:50

Message: 8 of 12

On 12/5/2012 12:44 PM, Matt wrote:
...
> - d starts from 0 and goes up to 1517 (not linear growing but still
> always growing)
> - time3 starts from 0 and goes up to 29.9 (growing linear)
>
> I can plot this set of results without any problem and I can spot for
> example that at time3=20, d=800. But when I'm trying to use the function :
>
> AAA=interp1(d, time3, 200, 'linear','extrap')
>
> It doesn't want to calculate it.

As noted in other response, cut'n paste actual values but one question
since you mention diagnostics via PLOT()...

What do

any(isnan(d))
any(isnan(time3))

return? PLOT will ignore NaN so perhaps there's a hidden problem.

Also, just for grins, try

AAA=interp1(d, time3, 200)

just to see if there's something funky on the options going on. I noted
in fooling around w/ the (much earlier) release here that using them
changed the behavior with the x=[0 3 2] funky case at least. One would
think it _shouldn't_ have any effect over the defaults when the values
are in range, but never hurts to check on stuff like that when things
don't seem straightforward.

--

Subject: Error using interp1 function

From: Steven_Lord

Date: 6 Dec, 2012 15:14:04

Message: 9 of 12



"dpb" <none@non.net> wrote in message news:k9o4a1$6ks$1@speranza.aioe.org...
> On 12/5/2012 11:46 AM, Matt wrote:
>> Thank you for your message.
>>
>> Well, I do not really understand what is the problem. The "d" value is
>> always growing, as is the "time3" value, so this shouldn't be a problem,
>> right ?
>
> Show the input vectors and line that creates the problem if it's not too
> long or try a subset that isn't that brackets the XI and hopefully that
> will cause same symptom w/o being excessively long.
>
> Nasser points out that the proscription I was thinking was in the doc
> isn't actually there; but it doesn't make any sense to try to interpolate
> when the x variable axis is multi-valued--what _should_ you get for
>
> interp1([0 3 2],[0 1 2],2.5)

That should return 1.5, which is exactly what you'd get from this similar
call:

interp1([0 2 3], [0 2 1], 2.5)

_Repeated_ values in x are ambiguous; if the value at x = 2 is specified to
be both 3 and 4, what should INTERP1 return if you asked it to interpolate
for xi = 2?

_Disordered_ values in x are not ambiguous. The interpolation functions may
sort the data for efficiency if it's not sorted (I don't remember off the
top of my head) but they should be okay handling the scrambled data.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Error using interp1 function

From: dpb

Date: 6 Dec, 2012 15:46:33

Message: 10 of 12

On 12/6/2012 9:14 AM, Steven_Lord wrote:
...

> _Disordered_ values in x are not ambiguous. The interpolation functions
> may sort the data for efficiency if it's not sorted (I don't remember
> off the top of my head) but they should be okay handling the scrambled
> data.

I did look; at least in this release it does sort() the vector.

That makes it work for one definition of working...it isn't the same as
I was pointing out that if one has X=[0 3 2] and XI = 2.5 as presented
there are two possible results if look at the linear ranges as ordered.

interp1() treats the data internally as if the call were

interp1([x,ix]=sort(x),y(ix),XI)

where I've expanded syntax to be smart in picking the desired return
value in embedding the sort() call in the argument list.

That's fine and I'll try to remember the behavior but probably should be
pointed out in the doc's...

I was thinking for some reason that it was solved the other way 'round
by disallowing the disordered input--don't remember now why. Probably
because at some point I wanted a piecewise version in some app years ago
and fiddled around w/ it...

I see I have made a couple of patches on interp1 here but they have to
do w/ the size() returned in a case where the number of columns was more
than the number of rows and internally the function used length()
instead of size(1) and thus swapped rows for columns and ended up
interpolating on rows instead of columns.

This latter is related somewhat to the discussion we had recently on the
expanded syntax that was proposing to remove the vectorized calling
syntax because it had been "enhanced" to the point of excessive
complexity between this release and current such that it was deemed
desirable to remove some of that added functionality.

Anyways, the last is a sidebar for sure...still would like to see Matt's
actual data and why he's getting no joy.

--

--

Subject: Error using interp1 function

From: rohith Eggidi

Date: 28 Jun, 2013 20:25:07

Message: 11 of 12

"Matt" wrote in message <k9nohk$c9f$1@newscl01ah.mathworks.com>...
> Hello everybody.
>
> After using the following function :
>
> --------------
> AAA=interp1(d, time3, 20, 'linear','extrap')
> --------------
>
> I'm getting the following error :
>
> --------------
> Error using griddedInterpolant
> The point coordinates are not sequenced in strict monotonic order.
> --------------
>
> Does anybody knows why ? d and time3 are both 1x330 double elements and basically I'm trying to
>
> I can provide more details is needed.
>
> Thanks a lot ! :-)

Since you said both d and time are increasing and the error say non monotonic, i think the problem is that the d is non decreasing i.e it could flatten for periods of time. this is probably why the interp1 function is throwing an error as it is picking up multiple times when d is at 20. I am currently facing a similar problem building empirical marginal distributions for a large data set and am looking for a solution. Please post if any insight on either issues.

Subject: Error using interp1 function

From: TideMan

Date: 28 Jun, 2013 21:51:59

Message: 12 of 12

On Saturday, June 29, 2013 8:25:07 AM UTC+12, rohith Eggidi wrote:
> "Matt" wrote in message <k9nohk$c9f$1@newscl01ah.mathworks.com>...
>
> > Hello everybody.
>
> >
>
> > After using the following function :
>
> >
>
> > --------------
>
> > AAA=interp1(d, time3, 20, 'linear','extrap')
>
> > --------------
>
> >
>
> > I'm getting the following error :
>
> >
>
> > --------------
>
> > Error using griddedInterpolant
>
> > The point coordinates are not sequenced in strict monotonic order.
>
> > --------------
>
> >
>
> > Does anybody knows why ? d and time3 are both 1x330 double elements and basically I'm trying to
>
> >
>
> > I can provide more details is needed.
>
> >
>
> > Thanks a lot ! :-)
>
>
>
> Since you said both d and time are increasing and the error say non monotonic, i think the problem is that the d is non decreasing i.e it could flatten for periods of time. this is probably why the interp1 function is throwing an error as it is picking up multiple times when d is at 20. I am currently facing a similar problem building empirical marginal distributions for a large data set and am looking for a solution. Please post if any insight on either issues.

This problem often arises when you have built a cumulative distribution function (CDF) from a histogram using cumsum, then try to interpolate. If one of the bins in the histogram is zero, then the CDF will have double probabilities for a particular value. The problem is easily fixed using unique:
[P1,indx]=unique(P);
v1=v(indx);

Tags for 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