%% 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.

rng('default')
P = -2.5 + 5*rand([50 2]);
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*rand([10 2]);

%
% 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)

% Copyright 2012 The MathWorks, Inc.