Fast way to multiply rows of a matrix with columns of another

I have two matrices and I want to multiply each column of the first with the row of the second to get a matrix, something like:

for j=1:size(A,2)
    c(:,:,j) = A(:,j)*B(:,j)'  ;
end

      

A

and B

are the same size.

Is there a quick way to do this?

+3


source to share


1 answer


Easy with bsxfun

:



C = bsxfun(@times, permute(A, [1 3 2]), permute(B, [3 1 2]));

      

+3


source







All Articles