How to multiply part of a matrix with another matrix
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ryan Bowman
il 7 Dic 2018
Commentato: Ryan Bowman
il 8 Dic 2018
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];
0 Commenti
Risposta accettata
James Tursa
il 7 Dic 2018
Modificato: James Tursa
il 7 Dic 2018
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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!