Fit a spline function to a set of data points

조회 수: 32(최근 30일)
Hi All,
I have a set of coordinate points
x= [0,4,6,10,15,20]
y = [18,17.5,13,12,8,10]
I want to fit a spline function.
Could someone please suggest the the curve fit function that can be used?
  댓글 수: 7
Deepa Maheshvare
Deepa Maheshvare 2022년 7월 3일
I tried
x = [0,4,6,10,15,20]
v = [18,17.5,13,12,8,10]
vq = interp1(x,v, 'linear', 'pp')
xq = x
vq1 = interp1(x,v,xq);
title('(Default) Linear Interpolation');
vq =
struct with fields:
form: 'pp'
breaks: [0 4 6 10 15 20]
coefs: [5×2 double]
pieces: 5
order: 2
dim: 1
orient: 'first'
Here I am not sure why the order (which I infer as the polynomial degree) is 2 for linear interpolation. Could you please explain this a bit?

댓글을 달려면 로그인하십시오.

채택된 답변

Sam Chak
Sam Chak 2022년 7월 3일
Thought you want the 'spline'? Is there a reason to use the 'linear' method?
x = [0, 4, 6, 10, 15, 20];
y = [18, 17.5, 13, 12, 8, 10];
xq = 0:0.01:20;
yq1 = interp1(x, y, xq, 'linear');
plot(x, y, 'o', xq, yq1, '--');
ylim([5 22]), grid on, title('Linear Interpolation');
yq2 = interp1(x, y, xq, 'spline');
plot(x, y, 'o', xq, yq2, '--');
ylim([5 22]), grid on, title('Spline Interpolation');
  댓글 수: 3
Deepa Maheshvare
Deepa Maheshvare 2022년 7월 4일
Thanks a lot for the clarification.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Simon Chan
Simon Chan 2022년 7월 3일
Use function spline


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!

Translated by