我從一個點集計算距離函數與距離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
你能給輸入和期望的輸出最小的例子嗎? –