Raw by column wise multiplication of matrices

3 次查看(过去 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
>>

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by