How to multiply part of a matrix with another matrix

11 ビュー (過去 30 日間)
Ryan Bowman
Ryan Bowman 2018 年 12 月 7 日
コメント済み: Ryan Bowman 2018 年 12 月 8 日
I have these two matrices M1 and M2. I'm trying to multiply M1 with the first two columns of M2 element by element (while not using a for loop). I've tried the dot multiplier and that hasn't worked. The result should just be one matrix.
M1 = [4 5; 3 1; 2 7];
M2 = [1 5 7; 3 10 4; 8 7 2];

採用された回答

James Tursa
James Tursa 2018 年 12 月 7 日
編集済み: James Tursa 2018 年 12 月 7 日
result = M1 .* M2(:,1:2);
If you want to replace part of M2 with this result, then simply
M2(:,1:2) = M1 .* M2(:,1:2);

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by