MATLAB Answers

Error in multipying a 3 by 3 matrix with a 3 by 1

2 ビュー (過去 30 日間)
Joshua Naah
Joshua Naah 2021 年 8 月 11 日
コメント済み: Joshua Naah 2021 年 8 月 11 日
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 '.*'.

回答 (1 件)

Alan Stevens
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!
  1 件のコメント
Joshua Naah
Joshua Naah 2021 年 8 月 11 日
Yh I just tried that and it didn't work. I should mention that am working in app designer, so when I first got the error I tried the same code in the command window and it worked just fine so am a bit surprised getting an error with the same code in app designer.

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by