MATLAB: Raw by column wise multiplication of matrices

array operationsmatrix multiplication

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.

Best Answer

>> 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
>>