Pairwise distance between two matrices of 3 columns and 1911 rows.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2020-7-11
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!