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