Create a Matrix with Euclidian Distances between Coordinates
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a 8x2x3 Matrix called "Dot_Space" with X and Y coordinates.
8 is the number of dots per row.
2 are the respective X and Y coordinates.
3 is the number of rows.
Now I would like to create a matrix that includes all euclidian distances between the dots.
% Euclidian distance between two points in two dimensional space: d(p,q) = sqrt((q1-p1)^2 + (q2-p2)^2)
for i = 1:length(Dot_Space)
for j = 1:length(Dot_Space)
for n = Number_of_Rows
if i ~= j
Distance(i,j,n) = sqrt((Dot_Space(i,1,n)-Dot_Space(j,1,n))^2 + (Dot_Space(i,2,n) Dot_Space(j,2,n))^2);
end
end
end
end
I assume that the amount of possible combinations/distances must exceed the size of the returned matrix and I forgot to implement something crucial. Someone with more experience in MatLab will probably be able to point out my mistake?!
Thank you very much!
댓글 수: 0
채택된 답변
KSSV
2022년 9월 20일
A = rand(8,2,3) ;
B = permute(A,[1 3 2]);
B = reshape(B,[],size(A,2),1) ;
iwant = squareform(pdist(B))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!