Question

How can I find the nearest points of two set of 3D points(with different number,set1 includes 400 points and set2 includes 2000 points) and then find the Euclidean distance between set1 and result from first part of the question?

Was it helpful?

Solution

You can use pdist2 to compute all distances and then pick the minimal distance.

allDist = squareform( pdist2( set1, set2 ) );
[minDist nni] = min( allDist, [], 2 ); 

Now minDist holds the minimal distance of each point in set1 to its nearest-neighbor (set2(nni)).

EDIT:
for low dimensional points (3 in this example) it should be more efficient to look at k-NN algorithms, as proposed in my other answer.

OTHER TIPS

Have you considered using k-Nearest Neighbors (kNN) search?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top