clc,clear,close all
[x,y]=meshgrid(-4:4 ); %生成已知的数据网格点
z=peaks(x,y ); %计算已知点的函数值
[x1,y1]=meshgrid(-4:0.25:4; 生成比%更精细的插值网格点
Z1=interp2(x,y,z,x1,y1,‘nearest’);
subplot(131 ),surf ) x1,y1,z1 ) %绘制基于最近邻法插值的三维表面图
xlabel(‘“最近法插值”)
Z2=interp2(x,y,z,x1,y1,‘linear’);
subplot(132 )、surf ) x1、y1、z2 ) %描绘基于二维分段线性插值三维表面图
xlabel(‘“分段线性插值”)
Z3=interp2(x,y,z,x1,y1,‘cubic’);
subplot(133 )、surf ) x1、y1、z3 ) %描绘基于二维三次多项式插值的三维表面图
xlabel(‘ (“三次多项式插值”)。