0
votes

I am using matlab and I have a certain set of x and y data,

x=[0,1.25,1.88,2.5,5,6.25,6.88,7.19,7.5,10,12.5,15,20];
y=[-85.93,-78.82,-56.95,-34.56,-33.57,-39.64,-41.96,-49.28,-66.6,-66.61,-59.16,-48.78,-41.53];

I want to use the curve fitting toolbox which has the spline function to generate a graph, so i did this,

cftool

It would bring me to the toolbox which i can then choose the spline fit. I was thinking if its possible that i extract the data points from the spline graph generated. Which means i probably would have more x and y data points than those that i input in, since the spline graph is sort of a continuous graph. Anyone could give me some advice on this? Thanks!

1

1 Answers

0
votes

You can perform the equivalent of the spline fit performed with cftool with fit, see for instance here, here, or here:

% perform spline fit without cftool
ft = fittype('cubicspline');
coeff=fit(x,y,ft); 

% use plot to display the interpolating polynomial 
% (relying on internal plot settings)
figure
h=plot(coeff,x,y,'o');

% extract the *interpolated* curve from the figure
xi=get(h,'XData');
yi=get(h,'YData');

Replot it just to show that we can:

enter image description here

But if you just want to interpolate do as Fraukje explained here. Define a finer grid on x and use the interp1 function, as in the following example (same x,y input data as before):

% interpolate 
Ni = 100;
xi = linspace(x(1),x(end),Ni);
yi = interp1(x,y,xi,'spline');

Now xi,yi is the interpolated data:

enter image description here