小编Win*_*nce的帖子

Matlab计算数组中所有(u,v)向量的最近邻距离

我试图计算nx2矩阵中最近邻居之间的距离,如下所示

point_coordinates =

   11.4179  103.1400
   16.7710   10.6691
   16.6068  119.7024
   25.1379   74.3382
   30.3651   23.2635
   31.7231  105.9109
   31.8653   36.9388





%for loop going from the top of the vector column to the bottom
for counter = 1:size(point_coordinates,1) 
    %current point defined selected 
    current_point = point_coordinates(counter,:);

    %math to calculate distance between the current point and all the points 
    distance_search= point_coordinates-repmat(current_point,[size(point_coordinates,1) 1]);
    dist_from_current_point = sqrt(distance_search(:,1).^2+distance_search(:,2).^2);

    %line to omit self subtraction that gives zero
    dist_from_current_point (dist_from_current_point <= 0)=[];

    %gives the shortest distance calculated for a certain vector …
Run Code Online (Sandbox Code Playgroud)

matlab for-loop vector distance matrix

1
推荐指数
1
解决办法
3588
查看次数

标签 统计

distance ×1

for-loop ×1

matlab ×1

matrix ×1

vector ×1