필터 지우기
필터 지우기

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