1、一维插值interp1 clc; 清除全部关闭; x0=0:1:2*pi; y0=sin(x0; x=0:0.5:2*pi; y=interp1(x0,y0,x,' spline ' ); figure(1; plot(x0,y0 ); 保持接通; 打印(x,y ); 网格打开; xlabel(x0 ); ylabel(y0 ); title ()喵); Legend(y0 )、(y );
2、二维插值interp2搜索范围:横坐标范围col(-5 ) ) ()5) ) ) ) ) ) ) ) )。
纵轴范围row(-3 ) ()3) ) ) ) ) )。
值域:与上述搜索范围一一对应
搜索坐标: (x,y ) ) ) ) )。
返回值:搜索坐标在搜索字段中获取的值
clc; 清除全部关闭; col=-5:5; row=-3:3; [map_x,map_y]=meshgrid(col,row ); forI=1:length(row ) forj=1: length (col ) region(i,j ) ) (I-1 ) * length (col ) j ) *10; 结束版本% % x : (-5 ) y:(-3 ) x=2.4; y=2.5; if x5 x=5; elseif x-5 x=-5; endif y3 y=3; elseif y-3 y=-3; endvalue=interp2(map_x,map_y,region,x,y ); fr intf (搜索) %d,%d ):%dn )、x、y、value ); simulink使用的插值模块: Lookup Tables