重复写命令看起来很蠢,我想使用循环的方法,但是出错了,希望大家帮忙改进改进,谢谢
x = [1,3,5,7,9,11,13,15,17,19];
x1 = 1:0.1:19;
y = [5.9,6.4,7.8,7.6,6.9,5.2,3.4,1.5,-0.7,-2];
s3 = [y1,y2,y3,y4,y5];
s2 = ['linear','nearest','pchip','spline'];
s1 = [p1,p2,p3,p4,p5];
for i=1:4
p = interp1(x,y,x1,s2(i));
s3(i) = polyval(p,xi)
end
% 以下是重复写的命令
p1 = interp1(x,y,x1,'linear');
p2 = interp1(x,y,x1,'spline');
p3 = interp1(x,y,x1,'pchip');
p4 = interp1(x,y,x1,'nearest');
p5 = polyfit(x,y,4)
xi = 10;
y1 = polyval(p1,xi)
y2 = polyval(p2,xi)
y3 = polyval(p3,xi)
y4 = polyval(p4,xi)
y5 = polyval(p5,xi)