Knnsearch: How to output disntace?

1 次查看(过去 30 天)
Here's the code. It basically finds the nearest sets of x,y,z points in the nodes array. Since the first column is the point itself, K=2, so that it finds the second nearest point. Then it generates a new array Near which sorts the data based on this new index.
Idx=knnsearch (nodes,nodes,'K',2)
Idx2=Idx(:,2)
Near=nodes(Idx2,:)
According to the documentation, there's an output argument D that should give the distance. But how do I implement it?

采纳的回答

Esen Ozbay
Esen Ozbay 2021-10-26
If you write
[Idx, dist] =knnsearch (nodes,nodes,'K',2);
you will obtain the distances mentioned in the documentation.
  1 个评论
Pelajar UM
Pelajar UM 2021-10-26
编辑:Pelajar UM 2021-10-26
Perfect. Thanks a lot!
Although some of the distances don't make a lot of sense. I'm trying to find the thickness of a 3D object. The generatemesh function was used to create nodes from an stl file. But the position of the nodes are quite random so I don't think Euclidean distance is the best approach for this problem.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by