Interpolated data from GRIDDATA fall outside specified interpolation limits
显示 更早的评论
Hi,
I want to create a contourplot of microhardness data taken on a weld. The data is in the form of 3 vectors: 1 vector "X" containing the x coordinate, 1 vector "Y" containing the y coordinate and 1 vector "HV" containing the microhardness data for every x-y position. The GRIDDATA function is used to create a regular grid from the non-uniform scattered data, so I expect NaN's in the interpolated "HV". Here is the code used to create the contour plot:
v = [200:20:400];
X_lin=linspace(min(X),max(X),1000);
Y_lin=linspace(min(Y),max(Y),1000);
[X_grid,Y_grid]=meshgrid(X_lin,Y_lin);
HV_grid=griddata(X,Y,HV,X_grid,Y_grid,'linear');
contourf(X_grid,Y_grid,HV_grid,v)
The resulting contour plot can be seen here:
The empty blue circles were obtained by plotting the X and Y vectors and represent the interpolation domain.
My concern is that their should not be HV values outside the range delimited by X and Y but we can clearly see that this is whats happening especially at the top of the contour. It is as if the griddata function extrapolated HV values outside the range given. It this behavior normal? Also is there a way to really limit the griddata to interpolate values within the strict range given by X and Y?
Thanks!
回答(1 个)
Hi Alexandre,
Sorry for the late reply; I just saw your question.
The interpolation appears correct to me, including the interpolated points which are "outside the range". Note that griddata is performing a 2d interpolation, and not multiple 1d interpolations. Imagine a rubber band stretched around all of your sample points, and you can see the area within which griddata will perform interpolation. In other words, it can interpolate to a query point which is contained within a triangle defined by any 3 of the sample points.
Hope this helps.
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!