Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
FInd distance between surface coordinates without repetition
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi
Suppose, I have list of 4 coordinates -
x[ -32.8778 -10.8573 11.3161 33.4895]
Y[-32.8778 -10.8573 11.3161 33.4895]
i want to calculate distance between all possible combinations (x and y) without repetition, in a for loop (as i need to perform this with larger dataset).
and getting a distance matrix along with coresponding x, y position.
could you please help me?
thanks in advance..!
0 commentaires
Réponses (2)
Marco Riani
le 12 Mai 2020
If x and y are
x=[ -32.8778 -10.8573 11.3161 33.4895];
y=[ -32.8778 -10.8573 11.3161 33.4895];
the distance matrix is
abs(x'-y)
0 22.0205 44.1939 66.3673
22.0205 0 22.1734 44.3468
44.1939 22.1734 0 22.1734
66.3673 44.3468 22.1734 0
or I am missing something of your question?
1 commentaire
Marco Riani
le 13 Mai 2020
Thanks for the clarification. Please let me know if the code below is what you wanted
% Define x and y
x=1:4;
y=2:5;
lx=length(x);
D=zeros(lx,lx);
for i=1:lx
for j=1:lx
D(i,j)=sqrt((x(i)-x(j))^2+(y(i)-y(j))^2);
end
end
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!