Finding the nearest neighbor to a single point in MATLAB

后端 未结 2 1882
心在旅途
心在旅途 2021-01-26 12:32

I\'m trying to do a nearest neighbor search that yields a single point as the single \"nearest neighbor\" to another point in matlab.

I\'ve got the following data:

2条回答
  •  悲&欢浪女
    2021-01-26 12:54

    You should first convert your grid to an n-by-2 matrix (if you created this using meshgrid, it's simply G = [XX(:) YY(:)]), you can then try it with pdist2 if you have the Statistics and Machine Learning Toolbox (which you do):

    [D,I] = pdist2(P, G, 'euclidian', 'Smallest', 1);
    

    Where G is the grid and P is your m-by-2 array of points to test.

提交回复
热议问题