MATLAB Answers

distance of points to points calculation

2 views (last 30 days)
Yu Li
Yu Li on 11 Jul 2018
Answered: Anton Semechko on 11 Jul 2018
Hi: I have two set of 2D scatter points, says A and B, I need the minimun value of each points in A to B. for example, the size of A and B are 100*2, and below are my codes:
for i=1:1:100
however, if the size of A and B are significantly large, for example: 1 million for each, the calculation cost significantly large amount of time.
so I want know if there is anyway to optimize this calculation?
Thanks Yu

Accepted Answer

Anton Semechko
Anton Semechko on 11 Jul 2018
Use 'knnsearch' function. For example:
will return indices of the points in set A closest to B, so that A(idxA(j),:) is the closest point to B(j,:). D_a2b(j) is the distance between these closest point pairs.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!