如何找到点集中一个点的第k个最近邻
我在二维平面上有一组点 (x,y)。给定点 (x0,y0) 和数字 k,如何找到点集中 (x0,x0) 的第 k 个最近邻。具体来说,点集由两个数组表示:x和y。点 (x0,y0) 由索引 i0 给出。这意味着 x0=x(i0) 和 y0=y(i0)。
Matlab中有什么函数或东西可以帮助我解决这个问题吗?如果Matlab没有这样的功能,您能建议其他有效的方法吗?
编辑:我必须计算集合中每个点 (x0,y0) 的这种距离。集合的大小约为 1000。k 的值应约为 sqrt(1500)。最糟糕的是我多次这样做。在每次迭代中,集合都会发生变化,我会再次计算距离。因此,运行时间是一个关键问题。
I have a set of point (x,y) on a 2d plane. Given a point (x0,y0), and the number k, how to find the k-th nearest neighbor of (x0,x0) in the point set. In detail, the point set are represented by two array: x and y. The point (x0,y0) is given by the index i0. It means x0=x(i0) and y0=y(i0).
Is there any function or something in Matlab helps me this problem. If Matlab doesn't have such kind of function, can you suggest any other effective ways.
EDIT: I have to calculate this kind of distance for every point (x0,y0) in the set. The size of the set is about 1000. The value of k should be about sqrt(1500). The worst thing is that I do this many times. At each iteration, the set changes, and I calculate the distances again. So, the running time is a critical problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您要对许多点进行此检查,您可能需要首先构建一个点间距离表
if you will do this check for many points you might want to construct a inter-point distance table first
如果您有统计工具箱,则可以使用函数knnsearch。
If you have the statistics toolbox, you can use the function knnsearch.
暴力算法将是这样的:
A brute force algorithm would be something like this:
免费开源的 VLFeat 工具箱包含 kd-tree 实现以及其他有用的东西。
The free and opensource VLFeat toolbox contains a kd-tree implementation, amongst other useful things.
蛮力方法看起来像这样:
The brute force approach looks something like this: