intexa.m
来自「matlab源代码,适用于开发研究,带来很好的学习效果.」· M 代码 · 共 30 行
M
30 行
%已知数据
t = 1900:10:1990;
p = [75.995 91.972 105.711 123.203 131.669...
150.697 179.323 203.212 226.505 249.633];
%使用不同的方法进行插值运算
x = 1900:0.01:1990;
yi_linear=interp1(t,p,x);
yi_spline=interp1(t,p,x,'spline');
yi_cubic=interp1(t,p,x,'cubic');
yi_v5cubic=interp1(t,p,x,'v5cubic');
%绘制对比图形
subplot(2,1,1);
plot(t,p,'ko');hold on;
plot(x,yi_linear,'g','LineWidth',1.5);hold on
plot(x,yi_spline,'y','LineWidth',1.5);
grid on;
title('Linear Vs Spline');
subplot(2,1,2);
plot(t,p,'ko');hold on;
plot(x,yi_cubic,'m','LineWidth',1.5);hold on
plot(x,yi_v5cubic,'k','LineWidth',1);
grid on;
title('Cubic Vs V5Cubic');
%创建新的图形窗口
figure
yi_nearest=interp1(t,p,x,'nearest');
plot(t,p,'ko');hold on;
plot(x,yi_nearest,'g','LineWidth',1.5);hold on
grid on;
title('Nearest Method')
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?