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

10 次查看(过去 30 天)
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.

采纳的回答

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

更多回答(2 个)

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

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by