?? interp1_example.m
字號:
%interp1_example.m
%用不同插值方法對一維數據進行插值,并比較其不同
x = 0:1.2:10;
y = sin(x);
xi = 0:0.1:10;
yi_nearest = interp1(x,y,xi,'nearset'); %最鄰近插值
yi_linear = interp1(x,y,xi); %默認插值方法是線性插值
yi_spline = interp1(x,y,xi,'spline '); %三次樣條插值
yi_cubic = interp1(x,y,xi,'cubic'); %三次多項式插值
yi_v5cubic = interp1(x,y,xi,'v5cubic'); %MATLAB5中使用的三次多項式插值
hold on;
subplot(2,3,1);
plot(x,y,'ro',xi,yi_nearest,'b-');
title('最鄰近插值');
subplot(2,3,2);
plot(x,y,'ro',xi,yi_linear,'b-');
title('線性插值');
subplot(2,3,3);
plot(x,y,'ro',xi,yi_spline,'b-');
title('三次樣條插值');
subplot(2,3,4);
plot(x,y,'ro',xi,yi_cubic,'b-');
title('三次多項式插值');
subplot(2,3,5);
plot(x,y,'ro',xi,yi_v5cubic,'b-');
title('三次多項式插值(MATLAB5)');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -