Error in multipying a 3 by 3 matrix with a 3 by 1
조회 수: 10 (최근 30일)
이전 댓글 표시
Xa = app.previewTABLE.Data(:,1);
Ya = app.previewTABLE.Data(:,2);
Za = app.previewTABLE.Data(:,3);
B = [DifX;DifY;DifZ];
C = [Xa;Ya;Za]; %% 3x1 matrix
Ri = [Sci Rz -Ry;-Rz Sci Rx;Ry -Rx Sci]; %%3x3 matrix
R = C * Ri
%%% This is the error am getting for trying to multiply a 3x3 matrix by a 3x1 (C * Ri).
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
댓글 수: 0
답변 (2개)
Alan Stevens
2021년 8월 11일
Check that the number of columns in the first matrix matches the number of rows in the second matrix.
Ri has 3 columns, C has 3 rows, so Ri*C will work, but with C having 1 column and R having 3 rows, C*Ri will not!
Steven Lord
2024년 2월 16일
Xa = app.previewTABLE.Data(:,1);
Ya = app.previewTABLE.Data(:,2);
Za = app.previewTABLE.Data(:,3);
C = [Xa;Ya;Za]; %% 3x1 matrix
Is this a 3-by-1 matrix? What size is app.previewTABLE.Data? If it is an m-by-n array, each of Xa, Ya, and Za will have m rows and C will be (3*m)-by-1 (unless app.previewTABLE.Data is a table array whose variables themselves have multiple columns.) That's only 3-by-1 if m is 1 (meaning app.previewTABLE.Data is a row vector.) From the name I suspect that it's not a row vector and so C isn't 3-by-1.
Ri = [Sci Rz -Ry;-Rz Sci Rx;Ry -Rx Sci]; %%3x3 matrix
You didn't show the definition of any of the variables you use here, so it's impossible to say that Ri is a 3-by-3 matrix. Let's say, for example, that each of Sci, Rz, Ry, and Rz were 2-by-2 matrices. This concatenation would be defined and would result in a 6-by-6 matrix not a 3-by-3.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!