Matlab学习第二天 利用插值

插入值一切手段:

2.插值的演示样例源代码:

%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’); %MATLAB 5 中使用的三次多项式插值 
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)’); 

版权声明:本文博主原创文章。博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/mengfanrong/p/4849660.html