MATLAB: How to multiply each element of a matrix by another matrix

MATLABmatrixmatrix by element multiplicationmatrix manipulationmatrix multiplicationmultiplication

Suppose two matrices A and B where B=[b11,b12,b13; b21,b22,b23; b31,b32,b33]
i would like to perform the following
C=[A*b11,A*b12,A*b13; A*b21,A*b22,A*b23; A*b31,A*b32,A*b33]
is there any appropriate way do this? faster than the for loop.
thank you in advance.

Best Answer

Use function kron:
>> B = reshape(1:9,3,[])
B =
1 4 7
2 5 8
3 6 9
>> A = 2*[1,1;1,1]
A =
2 2
2 2
>> kron(B,A)
ans =
2 2 8 8 14 14
2 2 8 8 14 14
4 4 10 10 16 16
4 4 10 10 16 16
6 6 12 12 18 18
6 6 12 12 18 18
>>