⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_interp2.m

📁 matlab从入门到精通第6章书后源码对初学者很有帮助
💻 M
字号:
% example_interp2.m
% 绘制二维插值图形
% 生成测量数据
[X,Y]=meshgrid(-3:0.5:3);
Z=peaks(X,Y);
% 生成插值数据矩阵
[XI,YI]=meshgrid(-3:0.25:3);
% 通过数据插值得到结果
ZI=interp2(X,Y,Z,XI,YI,'linear');
ZI_spline=interp2(X,Y,Z,XI,YI,'spline');
ZI_nearest=interp2(X,Y,Z,XI,YI,'nearest');
ZI_cubic=interp2(X,Y,Z,XI,YI,'cubic');
% 绘制二维线性插值数据
subplot(2,2,1);
mesh(X,Y,Z);
hold on;
mesh(XI,YI,ZI+20)
hold on;
plot3(X,Y,Z+20.2,'ok');
hold off;
title('figure1: interp2 with linear');
% 绘制二维样条插值数据
subplot(2,2,2);
mesh(X,Y,Z);
hold on;
mesh(XI,YI,ZI_spline+20)
hold on;
plot3(X,Y,Z+20.2,'ok');
hold off
title('figure2: interp2 with spline');
% 使用nearest方法绘制二维插值函数
subplot(2,2,3);
mesh(X,Y,Z);
hold on;
mesh(XI,YI,ZI_nearest+20)
hold on;
plot3(X,Y,Z+20.2,'ok');
hold off
title('figure3: interp2 with nearest');
% 使用cubic三次样条函数绘制二维插值函数
subplot(2,2,4);
mesh(X,Y,Z);
hold on;
mesh(XI,YI,ZI_cubic+20)
hold on;
plot3(X,Y,Z+20.2,'ok');
hold off
title('figure4: interp2 with cubic');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -