首页编程griddata,请教Matlab的griddata的用法

griddata,请教Matlab的griddata的用法

编程之家2023-11-0289次浏览

亲爱的读者们,你是否对griddata和请教Matlab的griddata的用法的相关问题感到困惑?别担心,今天我将为你解答这些问题,让你对此有更清晰的认识。

griddata,请教Matlab的griddata的用法

请教Matlab的griddata的用法

MATLAB散乱点插值函数

griddata函数

语法:

ZI= griddata(x,y,z,XI,YI)

[XI,YI,ZI]= griddata(x,y,z,XI,YI)

[...]= griddata(...,method)

griddata,请教Matlab的griddata的用法

[...]= griddata(...,method,options)

说明:

ZI= griddata(x,y,z,XI,YI)调整形如z= f(x,y)的曲面,使之与非等间距矢量(x,y,z)中的数据吻合。griddata函数在指定的(XI,YI)点处插补此曲面,生成ZI.此曲面一定通过这些数据点。 XI和 YI通常构成均匀网格(与meshgrid函数生成的相同). XI可以是行矢量,这种情况下该矢量确定一个具有固定列数的矩阵。与之类似,YI可以是列矢量,确定一个具有固定行数的矩阵。

[XI,YI,ZI]= griddata(x,y,z,XI,YI)函数返回与上述矩阵相同的插补后的矩阵ZI。并返回由行矢量XI和列矢量yi形成的矩阵XI和YI.后者与meshgrid函数返回的矩阵相同。

[...]= griddata(...,method)使用规定的插补方法:

'linear'基于三角形的线性插补法(缺省)

griddata,请教Matlab的griddata的用法

'cubic'基于三角形的三次插补法

'nearest'最近邻居插补法

'v4' MATLAB 4 griddata方法。

这些方法定义了匹配数据点的曲面类型。'cubic'和'v4'方法生成平滑曲面,而'linear'和'nearest'分别具有一阶导数和零阶导数不连续。除'v4'外所有方法基于数据的三角化。如果方法为[],则使用缺省的'linear'方法。

[...]= griddata(...,method,options)指定一串将通过delaunayn函数在Qhull中使用的单元阵列选项.如果选项为 [],则使用缺省的三角化选项。如果选项为{''},不使用任何选项,包括缺省选项。有时,griddata函数可能将位于数据凸壳上或靠近凸壳的点返回为NaNs。这是因为有时计算中的圆整处理使得很难确定一个靠近边界的点是否处于凸壳内。

算法:

griddata(...,'v4')命令使用 [3]中文档化的方法。其他griddata方法基于使用Qhull [2]的数据三角化。

实例:

对一个函数在±2.0范围内随机采样100点:

rand('seed',0)

x= rand(100,1)*4-2; y= rand(100,1)*4-2;

z= x.*exp(-x.^2-y.^2);

x, y,和 z均为包含非均匀采样数据的矢量。定义一个规范的网格,将数据与网格匹配:

ti=-2:.25:2;

[XI,YI]= meshgrid(ti,ti);

ZI= griddata(x,y,z,XI,YI);

Plot the gridded data along with the nonuniform data points used to generate it: mesh(XI,YI,ZI), hold

plot3(x,y,z,'o'), hold

MATLAB中的插值函数griddata()运行出现NAN怎么办

同遇到这个隐蔽的问题,解决了,所以顺便来挖坟答一下题。

========================================

没有griddata的具体实现算法方面的信息,但是插值原理应该是基于散乱数据点生成局部区域的插值查询。而且这个插值似乎是要求“内插”的,即查询点必须处于输入样本XY的”包围“状态中,否则就会报NaN查询结果。

matlab 2012a中的帮助是这样说的:

The method defines the type of surface fit to the data. The'cubic' and'v4' methods produce smooth surfaces while'linear' and'nearest' have discontinuities in the first and zero'th derivatives, respectively. All the methods except'v4' are based on a Delaunay triangulation of the data. If method is [], then the default'linear' method is used.

Occasionally, griddata might return points on or very near the convex hull of the data as NaNs. This is because roundoff in the computations sometimes makes it difficult to determine if a point near the boundary is in the convex hull.

========================================

所以这个问题无法避免。(虽然实测使用nearest方法没有产生NaN,但因没有解读其算法,不确定是否绝对不出现NaN结果)

如果只是为了绘出有效数据,把结果中的NaN数据删掉就行了。

如果想得到所有的查询值,把NaN结果全部取出来,相应的X,Y重新用nearest方法查询一次。或者自己写一个允许用近邻点外推插值的算法对其特殊处理。但还是会与griddata内部方法产生较大偏差,影响结果的”平滑性“。

GridLayout的几种常用设置

1.GridLayout设置:

GridLayout layout= new GridLayout();

//设置容器的列数

layout.numColumns= 4;

//设置容器上的组件是否等距分开

layout.makeColumnsEqualWidth= false;等价写法:GridLayout layout= new GridLayout(4, false);

2.GridData.grabExcessHorizontalSpace、GridData.grabExcessVerticalSpace

①GridData.grabExcessHorizontalSpace

GridData gridData= new GridData();

//当容器大小变化时,组件所在列空间横向随容器的变化而变化

gridData.grabExcessHorizontalSpace= true;等价写法:GridData gridData= new GridData(GridData.GRAB_HORIZONTAL);

②GridData.grabExcessVerticalSpace

GridData gridData= new GridData();

//当容器大小变化时,组件所在行空间纵向随容器的变化而变化

gridData.grabExcessVerticalSpace= true;等价写法:GridData gridData= new GridData(GridData.GRAB_VERTICAL);

3.GridData.FILL_HORIZONTAL、GridData.FILL_VERTICAL、GridData.FILL_BOTH

① GridData.FILL_HORIZONTAL:

GridData gridData= new GridData();

//横向对齐方式

gridData.horizontalAlignment= GridData.FILL;

gridData.grabExcessHorizontalSpace= true;等价写法:GridData gridData= new GridData(GridData.FILL_HORIZONTAL);

②GridData.FILL_VERTICAL

GridData gridData= new GridData();

//纵向对齐方式

griddata输入坐标不能是复数

我也出现了这个问题,通过查询及尝试其他插值函数发现,可能是导入的x,y,z的数据类型是表或者元胞数组,但参考点的数据类型应该是矩阵数组,因为插值过程中涉及到矩阵转置的计算,所以输入的数据必须是矩阵。类似地,interp2函数当中的xyz也应当是矩阵数组。

文章分享结束,griddata和请教Matlab的griddata的用法的答案你都知道了吗?欢迎再次光临本站哦!

定制开发 什么是软件定制开发怎么设计网站?怎么建网站呀!