Raw by column wise multiplication of matrices
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sib RV
am 30 Jul. 2020
Bearbeitet: Sib RV
am 30 Jul. 2020
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 Kommentare
Akzeptierte Antwort
Bruno Luong
am 30 Jul. 2020
Bearbeitet: Bruno Luong
am 30 Jul. 2020
>> 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!