I have 1000 coordinates. How can I find the distance between every combination with out repeats? Thank you!

1 回表示 (過去 30 日間)
I have 1000 coordinates and I need to find the distance between every combination. I tried using a nested loop to cycle through every combination but the diagonals of the matrix (1,1) (2,2) etc. are not needed and (1,2) is the same as (2,1) and ( 1,3) is the same as (3,1) so the whole top half or bottom half is not needed. Is there another way to do this since creating an 1000 by 1000 matrix where more than half of the data is not needed seems computationally wasteful. Ultimately i want to find pairs where the distance is under a threshold(RU) then apply another condition to these pairs using their normal vectors Thank you!!!
RU = 13
for k = 1 : num_tags
for j = 1: num_tags
Distance = norm(midplat(k) - midplat(j)); % trys every combination of platlets to find distances within a tolarance
%
if (Distance < RU && Distance ~= 0 )
normk = mol_normals(k,:);
normj = mol_normals(j,:);
if (abs(dot(normk,normj))> .95)
matrixkj(k,:) = [k,j]; % want to save the pairs in a matrix to call outside of the loop
end
end
end
end

採用された回答

KSSV
KSSV 2017 年 8 月 23 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by