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!