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

14 ビュー (過去 30 日間)
Victor
Victor 2011 年 2 月 28 日
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 Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by