Info
此问题已关闭。 请重新打开它进行编辑或回答。
FInd distance between surface coordinates without repetition
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Marco Riani
2020-5-12
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 个评论
Marco Riani
2020-5-13
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 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!