How to multiply each element of a matrix by another matrix

12 ビュー (過去 30 日間)
Oussama GASSAB
Oussama GASSAB 2019 年 4 月 26 日
編集済み: Oussama GASSAB 2019 年 4 月 26 日
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.

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 4 月 26 日
編集済み: Andrei Bobrov 2019 年 4 月 26 日
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
>>

その他の回答 (1 件)

Oussama GASSAB
Oussama GASSAB 2019 年 4 月 26 日
編集済み: Oussama GASSAB 2019 年 4 月 26 日
thank you so much for your answer, it works so well and it is so fast.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by