我从一个点集计算距离函数与距离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,:)];
现在我想只得到独特的点对。因此,对于我的代码,点对A-B将被计数两次为A-B和B-A,但我只需要对A-B进行计数(其他对将被擦除)。任何简单的方法去解决它?谢谢。
使用'unique' ... – bla
你能给输入和期望的输出最小的例子吗? –