Azzera filtri
Azzera filtri

Matrix Multiplication (multiply every row of a matrix to different values)

10 visualizzazioni (ultimi 30 giorni)
Dear all,
I am looking for a way to multiply every row of a matrix to different values? Let assume we have:
A=[1, 2, 3; 4, 5, 6; 7, 8, 9]
B=[a;b;c]
I am looking for a way to have:
C=[1*a, 2*a, 3*a; 4*b, 5*b, 6*b; 7*c, 8*c, 9*c]
Thanks in advance for your comments.

Risposta accettata

Sean de Wolski
Sean de Wolski il 28 Feb 2011
or
C=bsxfun(@times,A,B);

Più risposte (2)

Paulo Silva
Paulo Silva il 28 Feb 2011
Just a little interesting thing I've done
syms a b c
A=[1, 2, 3; 4, 5, 6; 7, 8, 9]
B=[a;b;c];C=[];
for id=1:numel(B)
C=[C A(id,:)*B(id)];
end
C
The symbolic result (only works if you have the symbolic toolbox and a valid license for it) is
[ a, 2*a, 3*a, 4*b, 5*b, 6*b, 7*c, 8*c, 9*c]
The result is symbolic and you can use the subs function to replace the letters by numbers.

Victor
Victor il 28 Feb 2011
Dear all, thanks.

Categorie

Scopri di più su Symbolic Math Toolbox 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!

Translated by