Create a Matrix with Euclidian Distances between Coordinates
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Gabriel Germann
le 20 Sep 2022
Commenté : Gabriel Germann
le 20 Sep 2022
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 commentaires
Réponse acceptée
KSSV
le 20 Sep 2022
A = rand(8,2,3) ;
B = permute(A,[1 3 2]);
B = reshape(B,[],size(A,2),1) ;
iwant = squareform(pdist(B))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!