How do I allocate one point only in matrix A to its closest point in matrix B
3 views (last 30 days)
Show older comments
Hello everyone!
relatively new to MATLAB and would like some help.
I have 2 2D points arrays A, B. I need to connect each point in matrix A to its closest point in matrix B.
The issue is that I can connect just 1 point from A to just 1 point in B. So if a point in A is further away from all the points in B then all other points in A I need to discard it.
This complicates things because it becomes recursive.. and I'm not sure how to implicate this.
If anyone has an idea or advice it will be awesome!
Thanks!
0 Comments
Answers (1)
KSSV
on 24 Oct 2020
Edited: KSSV
on 24 Oct 2020
Read about knnsearch. This function will give you the number points you specified which are close.
idx = knnsearch(B,A) ;
B(idx,:) % these are the points in B close to A
2 Comments
KSSV
on 24 Oct 2020
You need not to bother about that....you specify that you need one point in knnsearch, it will give the closest point.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!