How to find two nearest points?

Hey guys I need your help,
I have a point x and want to find the two nearest points from a path. I work with knnsearch but I don't get coordinates as my result. This is how my code works:
x=T(1:3,4)';
newpoint=path1;
Mdl = KDTreeSearcher(newpoint)
Idx = knnsearch(Mdl, x, 'K', 2);
as a result I get:
Idx =
619 620
The problem is, that I need the coordinates of the two nearest points.
Can anyone help?

回答 (1 件)

Star Strider
Star Strider 2016 年 9 月 24 日

1 投票

The knnsearch function is a classifier.
For points defined by (x,y) coordinates, the pdist (or pdist2) functions would likely be most appropriate. These functions will give you the distances. You then need to threshold them to find the points that meet your criteria.

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

質問済み:

2016 年 9 月 24 日

回答済み:

2016 年 9 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by