Raw by column wise multiplication of matrices

8 ビュー (過去 30 日間)
Sib RV
Sib RV 2020 年 7 月 30 日
編集済み: Sib RV 2020 年 7 月 30 日
I want to multiply each row of a matrix with corresponding column(only) of another matrix so that the answer is a column vector.
I know how to do it with for loop. But I am already doing it inside a loop, so want to avoid another loop. Thank you for any suggestions.

採用された回答

Bruno Luong
Bruno Luong 2020 年 7 月 30 日
編集済み: Bruno Luong 2020 年 7 月 30 日
>> A=randi(10,4,3)
A =
6 5 4
3 4 1
8 4 10
2 8 10
>> B=randi(10,3,4)
B =
2 4 3 5
1 5 5 4
9 8 9 10
>> c = sum(A.'.*B)
c =
53 40 134 142
>> Ct = diag(A*B) % WARNING: many unnecessary calculations by this method
Ct =
53
40
134
142
>> A(1,:)*B(:,1)
ans =
53
>> A(4,:)*B(:,4)
ans =
142
>>
  1 件のコメント
Sib RV
Sib RV 2020 年 7 月 30 日
編集済み: Sib RV 2020 年 7 月 30 日
Thank you :). This is what I wanted.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by