Pairwise distance between two matrices of 3 columns and 1911 rows.
조회 수: 3 (최근 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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
