# Interpolate non-monotonic test data

2 views (last 30 days)
Konstantinos Belivanis on 6 Aug 2015
Commented: Walter Roberson on 17 Aug 2015
Hello all,
I want to interpolate at specific values the curve in the picture attached (say every 0.01 in the x axis). Any idea how? The test data consists of a huge number of data points, so I want to clean them a bit.
Thanks Konstantinos Belivanis on 16 Aug 2015
What I did was to run through all the data for the amount of times I wanted and interpolated when the point of interest was between the data. The code I used was:
k=1;
lo=50;
ul=49;
i=k;
j=1;
i=1;
for j = 1:lo
x1=0;
x2(j,1)=j/100;
while x2(j,1)>=x1
x1=A(i,1);
x3=A(i+1,1);
y1=A(i,2);
y3=A(i+1,2);
if x2(j,1)<x3
B(j,1)=j/100;
B(j,2)=(x2(j,1)-x1)*(y3-y1)/(x3-x1)+y1;
y2(j,1) = B(j,2);
end
i=i+1;
end
end
k=i;
l=length(x2);
j=1;
for j = 1:ul
x1=lo/100;
x2(j+l,1)=lo/100-j/100;
while x2(j+l,1)<=x1
x1=A(k,1);
x3=A(k+1,1);
y1=A(k,2);
y3=A(k+1,2);
if x2(j+l,1)>x3
B(j+l,1)=lo/100-j/100;
B(j+l,2)=(x2(j+l,1)-x1)*(y3-y1)/(x3-x1)+y1;
y2(j+l,1) = B(j+l,2);
end
k=k+1;
end
end
etc... for as many cycles I wanted it. It worked well.
Image Analyst on 17 Aug 2015
Without comments, that's rather daunting to try to understand. You might like to look up interp1() if you want to fill in missing data. But again, interp1() or any interpolation, even if the sampled points are less frequent, will still be noisier than regression.

Image Analyst on 7 Aug 2015
Try interp1(). By the way, interpolation won't "clean" the data. Why do you think it will? It will just give you more points in between the noisy ones. Perhaps you meant "regress" instead of "interpolate"??? If you meant regress, see my attached demo on polyfit().
Please READ THIS and then attach your screenshot (which you forgot to attach), and original data file, and maybe some code to read in the data file.
Walter Roberson on 17 Aug 2015