Why does the GRIDDATA function from MATLAB produce different results than that of a very simple 1-nearest neighbor algorithm?

조회 수: 6 (최근 30일)
Why does the GRIDDATA function from MATLAB produce different results than that of a very simple 1-nearest neighbor algorithm?
When I use the nearest neighbor algorithm from GRIDDATA, the results obtained are different from a very simple implemenation, such as:
xb = 2342323; % x-coordinate of point to search for
yb = 13254; % y-coordinate of point to search for
for ii=1:length(X)
xa=X(ii);
ya=Y(ii);
dis=sqrt((xa-xb)^2+(ya-yb)^2);
if dis<dism
ind=ii;
dism=dis;
end
end
zb = Z(ind) % interpolated z-value of searched point
Furthermore, I receive a warning for duplicate points that is not true:
Warning: Duplicate x-y data points detected: using average of the z values.
(Type "warning off MATLAB:griddata:DuplicateDataPoints" to suppress this warning.)
> In D:\MATLAB6p5p1\toolbox\matlab\polyfun\griddata.m at line 59
In q:\1400113\ex.m at line 24
Why does this occur?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
This bug has been fixed for Release 14 SP1 (R14SP1). For previous releases, please read below for any possible workarounds:
GRIDDATA uses a Delaunay triangulation of the data to perform its analysis. When the data has strange scaling, this algorithm might detect points that are very close to each other (relative to the absolute value) and see them as duplicates.
GRIDDATA then uses an averaged z-value for these points, which can lead to different results compared to the simple algorithm.
As a workaround, remove large offsets from the data, so that the ratio of the variance of the data to the mean value of the data increases. The following code illustrates how you can do this:
% get offset values
xmin = min(X);
ymin = min(Y);
% correct for offset
X = Y - xmin;
Y = Y - ymin;
%remove offset also fromcoordinates of point to search for
xb = xb - xmin;
yb = yb - ymin;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by