www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/NearestNeighborInterpolationUsingadelaunayTriangulationQExample.m

    %% Nearest-Neighbor Interpolation Using a delaunayTriangulation Query   
% This example shows how to perform nearest-neighbor interpolation on a
% scattered set of points using a specific Delaunay triangulation.

%% 
% Create a |delaunayTriangulation| of a set of scattered points in 2-D. 
P = -2.5 + 5*gallery('uniformdata',[50 2],0);
DT = delaunayTriangulation(P)  

%% 
% Sample a parabolic function, _V(x,y)_, at the points specified in |P|. 
V = P(:,1).^2 + P(:,2).^2;  

%% 
% Define 10 random query points. 
Pq = -2 + 4*gallery('uniformdata',[10 2],1);  

%% 
% Perform nearest-neighbor interpolation on |V| using the triangulation,
% |DT|. Use |nearestNeighbor| to find the indices of the nearest-neighbor
% vertices, |vi|, for the set of query points, |Pq|. Then examine the
% specific values of |V| at the indices.
vi = nearestNeighbor(DT,Pq);
Vq = V(vi)