From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Multiplying row of matrix by vector many times
Date: Mon, 15 Mar 2010 07:29:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <hnknk1$l33$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1268638145 21603 (15 Mar 2010 07:29:05 GMT)
NNTP-Posting-Date: Mon, 15 Mar 2010 07:29:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1443642
Xref: comp.soft-sys.matlab:616784


I have an m x n matrix A, and a set of p vectors of length n (a p x n matrix B)

If v is a vector in B I would like to compute A.*repmat(v, [m 1]) and I would like to do this for all p vectors.

For example if 
A = [1 2 3; 4 5 6]
v = [0 0 1]

I want
[0 0 3; 0 0 6]

and I need to do this for all p vectors.

Is there any way for me to do this without resorting to loops?  I was thinking of using 3D matrices and first converting A to repmat(A, [1 1 p]) but then converting B to the desired 3D matrix is tricky without a loop.

Any suggestions?


p.s. If it matters, after finding C = A.*repmat(v, [m 1])  I would like to take the horizontal sum and store this vector somewhere and do this p times