I have a set of xy points:
x = [1 2 3 3 2]
y = [1 1 2 3 2]
I would like to do an interpolation of those point. My issue is, interp1() or splin() require a strictly ecreasing x.
How can I get an interpolation like this:
x = [1 2 3 4 5]
y = [1 1 2 3 2]
xx = linspace(1, 5, 100);
yy2 = interp1(x, y, xx, 'spline');
plot(xx',yy2)
scatter(x, y)
But with a non increasing x ?
I do not only need the plot, but also get the interpolation value for a given x and y.
This is a parametric curve, you have to consider a third vector t
(the values of the parameter) and compute two splines. You can change the spline type by changing the third parameter (see the splin
help page):
x = [1 2 3 3 2];
y = [1 1 2 3 2];
t = 1:5;
dx = splin(t,x,"natural");
dy = splin(t,x,"natural");
tt=linspace(t(1),t($),1000);
plot(interp(tt,t,x,dx),interp(tt,t,y,dy),x,y,'o')