Matlab 获取唯一的点对

Matlab 获取唯一的点对,matlab,Matlab,我正在计算一组点的距离函数,以选择距离x的特定公差d的点,并编写了以下代码: function pts_pairs = donut_neighbor(pts,x,d) % Matrix of pts repeated for the total number of points temp_pts1 = repmat(pts,size(pts,1),1); % Matrix of pts where each row is repeated total number of point times

我正在计算一组点的距离函数,以选择距离x的特定公差d的点,并编写了以下代码:

function pts_pairs = donut_neighbor(pts,x,d)
% Matrix of pts repeated for the total number of points 
temp_pts1 = repmat(pts,size(pts,1),1);
% Matrix of pts where each row is repeated total number of point times
% Uses kronecker product which repeats all the elements 
temp_pts2 = kron(pts,ones(size(pts,1),1));
% Compute the distance between the matrices 
dist = sqrt((temp_pts1(:,1)-temp_pts2(:,1)).^2 + (temp_pts1(:,2)-temp_pts2(:,2)).^2);
% Get indices of the point pairs in the donut
ind = dist > (x-d/2) & dist < (x+d/2);
% output point coordinates of the point pairs
pts_pairs = [temp_pts1(ind,:) temp_pts2(ind,:)];
函数pts\u pairs=donut\u邻居(pts,x,d)
%总点数重复的pts矩阵
temp_pts1=repmat(pts,尺寸(pts,1),1);
%pts矩阵,其中每行重复总点数
%使用kronecker产品,重复所有元素
temp_pts2=克朗(分,个(分,1),1);
%计算矩阵之间的距离
dist=sqrt((temp_pts1(:,1)-temp_pts2(:,1))。^2+(temp_pts1(:,2)-temp_pts2(:,2))。^2);
%获取圆环中点对的索引
ind=dist>(x-d/2)和dist<(x+d/2);
%点对的输出点坐标
pts_pairs=[temp_pts1(ind,:)temp_pts2(ind,:)];

现在我只想得到唯一的点对。因此,对于我的代码,点对A-B将被计数为A-B和B-A的两倍,但我只希望对A-B进行计数(另一对将被擦除)。有什么简单的方法吗?谢谢。

我想你有这样的东西:

pts_pairs =

     1     2
     1     3
     3     4
     2     1
     3     1
     4     5
unique(sort(pts_pairs, 2), 'rows')
例如,如果1与2相关,而2与1相关,则只希望保留一个眼波。你可以这样做:

pts_pairs =

     1     2
     1     3
     3     4
     2     1
     3     1
     4     5
unique(sort(pts_pairs, 2), 'rows')
其中:

ans =

     1     2
     1     3
     3     4
     4     5

你能给出一个输入和期望输出的最小示例吗?