Pairwise distance between two matrices of 3 columns and 1911 rows.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vahid Esmaeili
le 10 Juil 2020
Commenté : Vahid Esmaeili
le 13 Juil 2020
Hello,
Hello.
I have two questions.
1)- I have two matrices of 3 columns and 1911 rows (matrices have similar dimensions).
In fact, each matrix consists of the data of a moving marker in 3D space. 1st column returns the amount of movement of the marker in the X vector (anteroposterior direction). 2nd column returns the amount of movement of the marker in the Y vector (vertical direction). 3rd column returns the amount of movement of the marker in the Z vector (mediolateral direction). The number of the rows is actually the number of frames that these 3 parameters have been recorded. I have to calculate the distance between each member of matrix A with the corresponding member of matrix B (e.g. 1st member of matrix A (which is the movement of the marker in the anteroposterior direction) with the 1st member of matrix B (which again is the movement of the marker in the anteroposterior direction). sqrt(sum((A - B) .^ 2)) just provides me with 7.6257 37.2261 5.2263 (for each column) while I have to calculate the distance of all 5733 (3*1911) memebrs of matrix A with corresponding member of matrix B.
2)- What I have to do if the number of rows of matrix A is not similar to the number of rows of matrix B?
I appreciate your kind attention to my request.
4 commentaires
Réponse acceptée
Voss
le 11 Juil 2020
Sounds like you need to do the sum over the second dimension of (A-B).^2; that is, to sum the sqaured differences of positions in each of the X-, Y-, and Z-dimensions in space.
sqrt(sum((A - B) .^ 2,2))
See the documentation for sum for further clarification.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!