Simple array multiplication of incompatible sized arrays

13 ビュー (過去 30 日間)
olivia
olivia 2023 年 9 月 5 日
コメント済み: olivia 2023 年 9 月 6 日
I would like to multiply these two arrays of different size and I am recieving the error :
"Arrays have incompatible sizes for this operation"
which makes sense, researching this question on other forums I found you can "Pad with zeros" and I would like to do that but I don't know how.
NEDsv=NED*SV;
%SV is a 62x3 double
%NED is a 186x3 double
  1 件のコメント
Clay Swackhamer
Clay Swackhamer 2023 年 9 月 5 日
I think matrix multiplication requires that the first matrix must have the same number of columns as the number of rows in the second matrix. So can you just transpose SV like this:
NEDsv = NED * SV'

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

採用された回答

dpb
dpb 2023 年 9 月 5 日
移動済み: dpb 2023 年 9 月 5 日
What KIND of "multiply"? "*" is matrix multiplication and
SV=rand(62,3);
NED=rand(186,3);
M=NED*SV.';
whos M
Name Size Bytes Class Attributes M 186x62 92256 double
so you can multiply them if you transpose the second...of course, that may not be what you had in mind; you didn't tell us what you expected the result to be, but if one takes the hint about augmenting with zeros, then
M=NED.*[SV;zeros(size(NED,1)-size(SV,1),size(NED,2))];
whos M
Name Size Bytes Class Attributes M 186x3 4464 double
Of course, this is <element-wise multiplication>, something much different than <matrix multiplication> and uses the "dot" operator ",*".
  3 件のコメント
dpb
dpb 2023 年 9 月 5 日
@Bruno Luong -- chuckle...blame "fat fingers" instead....
olivia
olivia 2023 年 9 月 6 日
@dpb thank you very much. I am also not sure what to expect for the result... :D but this worked

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by