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 CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by