Filter löschen
Filter löschen

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

8 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

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

Weitere Antworten (2)

Paulo Silva
Paulo Silva am 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 am 28 Feb. 2011
Dear all, thanks.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by