interp1: The grid vectors are not strictly monotonic increasing
4 views (last 30 days)
Show older comments
Hi!
I want to interpolate a set of x-,y-values (2D-coordinates). My problem is the error in title.
I watched for a solution in web, but that didn't solve my problem. What I tried:
if
% My code:
xi = 0:0.1:length(x);
[x,index] = sort(x);
yi = interp1(x,y(index),xi);
% End of my code
end
But same Error...
PS: how do integrate the code here?
Greetings, Max
0 Comments
Accepted Answer
Matt J
on 5 Sep 2014
Edited: Matt J
on 5 Sep 2014
The data you've plotted here suggests that you're really trying to interpolate a space curve, not a function. Consider this FEX file instead,
Alternatively, if you can write your curve in the parametric form x(t),y(t) you can interpolate both x and y with respect to t using the spline() command.
More Answers (2)
Guillaume
on 5 Sep 2014
Edited: Guillaume
on 5 Sep 2014
My guess is that you have some values of x that repeat thus it's not strictly monotonic. If you're happy just discarding all but one of the y for the repeating x the following will work:
xi = 0:0.1:length(x);
[x, index] = unique(x); %sort and remove duplicates
yi = interp1(x, y(index), xi); %edited for typo in interp1 name
If you want something more complex for the duplicates (like mean) you'll have to say what.
4 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!