How to find the nearest points to given coordinates with MATLAB?

后端 未结 2 1495
南旧
南旧 2021-01-20 17:59

I need to solve a minimization problem with Matlab and I\'m wondering which is the easiest solution. All the potential solutions that I\'ve been thinking in require lot of p

2条回答
  •  [愿得一人]
    2021-01-20 18:07

    Let Lat and Long denote latitude and longitude matrices, then

    dist2=sum(bsxfun(@minus, cat(3,A,B), cat(3,Lat,Long)).^2,3);
    [I,J]=find(dist2==min(dist2(:)));
    

    I and J contain the indices in A and B that correspond to nearest point. Note that if there are multiple answers, I and J will not be scalar values, but vectors.

提交回复
热议问题