Error using Interp1 function

4 views (last 30 days)
Andrew
Andrew on 7 Apr 2014
Edited: John D'Errico on 7 Apr 2014
I have data taken at non-regular intervals, and I'd like to interpolate the data to have values for x-coordinates from 10 to 100. I'm trying to use interp1 to do this on two different data sets- for one set it works fine and for the other, I get the error
Error using gridded Interpolant The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 191) F = griddedInterpolant(X,V,method);
I've already used the unique() function to ensure the data is increasing and there are no duplicate points.
This code, using dataset 1 (attached) results in the error:
permaxload_t1_interp=[10:1:100];
Etot_t1_interp=interp1(t1_ordered(1, :), t1_ordered(2, :), permaxload_t1_interp);
While this code successfully interpolates, using dataset 3 (attached):
permaxload_t3_interp=[10:1:100];
Etot_t3_interp=interp1(t3_ordered(1, :), t3_ordered(2, :), permaxload_t3_interp);
I'd appreciate any insight, thanks.

Answers (1)

John D'Errico
John D'Errico on 7 Apr 2014
Edited: John D'Errico on 7 Apr 2014
So, is the vector t1_ordered(1,:) monotonically increasing? READ THE ERROR MESSAGE.
When I take your data and use diff on it, some of the differences are exactly zero, so you have replicates. How should it interpolate if you have two points at the same location for the independent variable?
ALWAYS look at your data. Don't just throw it into a tool and wonder what happened.
t = t1_ordered(1,:);
find(diff(t) == 0)
ans =
110 127
y = t1_ordered(2,:);
y([110 111 127 128])
ans =
0.013131 0.013501 0.016223 0.016328
So while the points have the same value for the independent variable, the dependent variable has changed. You are trying to interpolate a function which is not single valued.
My consolidator tool is useful for exactly this problem. It looks for replicates in x, averaging the y values. Find it on the file exchange.

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!