Raw by column wise multiplication of matrices
8 ビュー (過去 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.
0 件のコメント
採用された回答
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
>>
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!