MATLAB Answers

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

2 views (last 30 days)
Jonathan Salazar
Jonathan Salazar on 23 Aug 2017
Answered: KSSV on 23 Aug 2017
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by