【MATLAB建模学习实录【三】】插值与拟合、数据处理

散点差值模板:使用griddata函数

例:给定一些离散的点坐标与对应深度,该区域对应的图形。

板子如下:

clc,clear
x=[129,140,103.5,88,185.5,195,105,157.5,107.5,77,81,162,162,117.5];
y=[7.5,141.5,23,147,22.5,137.5,85.5,-6.5,-81,3,56.5,-66.5,84,-33.5];
z=-[4,8,6,8,6,8,8,9,9,8,8,9,4,9];
xmn=minmax(x);
ymn=minmax(y);
xi=xmn(1):xmn(2);
yi=ymn(1):ymn(2);
yi=yi';
zi1=griddata(x,y,z,xi,yi,'cubic');
zi2=griddata(x,y,z,xi,yi,'nearest');
zi=zi1;
zi(isnan(zi1))=zi2(isnan(zi1));
subplot(1,2,1),plot(x,y,'*')
subplot(1,2,2),mesh(xi,yi,zi)

注意,xi和yi是需要相同维数或者一行一列的向量,于是在处理之前需要将yi进行转置,不然会报错。

posted @ 2020-09-09 20:04  BeyondW  阅读(160)  评论(0编辑  收藏  举报