How to multiply each element of a matrix by another matrix
12 views (last 30 days)
Show older comments
Oussama GASSAB
on 26 Apr 2019
Edited: Oussama GASSAB
on 26 Apr 2019
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.
0 Comments
Accepted Answer
Andrei Bobrov
on 26 Apr 2019
Edited: Andrei Bobrov
on 26 Apr 2019
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
>>
0 Comments
More Answers (1)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!