MATLAB中的插值函数griddata()运行出现NAN怎么办?? 20
2个回答
展开全部
同遇到这个隐蔽的问题,解决了,所以顺便来挖坟答一下题。
========================================
没有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内部方法产生较大偏差,影响结果的”平滑性“。
========================================
没有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内部方法产生较大偏差,影响结果的”平滑性“。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询