Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

FInd distance between surface coordinates without repetition

1 visualización (últimos 30 días)
Abhilash Uniyal
Abhilash Uniyal el 12 de Mayo de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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..!

Respuestas (2)

Marco Riani
Marco Riani el 12 de Mayo de 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 comentario
Abhilash Uniyal
Abhilash Uniyal el 13 de Mayo de 2020
ok let me put this way.
I have 4 different coordinates.
ex point 1 =x(1),y(1)
from which i have saparated each x position and y position.
x=[x1 x2 x3 x4]
y=[y1 y2 y3 y4]
distance from point 1 to 2-
point 1 to 2=sqrt(y(1)-y(2))^2+(x(1)-x(2))^2);

Marco Riani
Marco Riani el 13 de Mayo de 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

Community Treasure Hunt

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

Start Hunting!

Translated by