multiply lines of a matrix by a line

3 次查看(过去 30 天)
Martin
Martin 2013-9-13
Hi,
given a matrix A = (Aij) and an horizontal array b = (bj), with B and A of the same width, is there a command that returns a matrix C of the same size as A, and whose each element Cij = Aij * bj ?
I tried C = A .* b but it only works when A is an array as b.
Thanks!

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2013-9-13
编辑:Andrei Bobrov 2013-9-13
try bsxfun:
C = bsxfun(@times,A,b);

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by