MATLAB: Closest point in a set based on distance

matrix

Given two sets of points, how can we find the point in set B that is closest distance-wise from the points in set A?
Eg., A = [(0, 0), (-1, 0), (0, -1), (-1, -1)] ; B = [(1, 1), (1, 2), (2, 1), (2, 2)]. Then the point (1, 1) is closest to set A (at the point (0, 0) with a distance of 1.41)

Best Answer

Use pdist2.
Best wishes
Torsten.