Thread Subject: Multiplying row of matrix by vector many times

Subject: Multiplying row of matrix by vector many times

From: Louis

Date: 15 Mar, 2010 07:31:02

Message: 1 of 4

Hi,

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?

Thanks

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

Subject: Multiplying row of matrix by vector many times

From: James Tursa

Date: 15 Mar, 2010 08:01:17

Message: 2 of 4

"Louis" <tanlouiss+matlab@gmail.com> wrote in message <hnknnm$mlh$1@fred.mathworks.com>...
> Hi,
>
> 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?
>
> Thanks
>
> 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

A * B.'

Am I missing something?

James Tursa

Subject: Multiplying row of matrix by vector many times

From: Umit

Date: 15 Mar, 2010 10:00:22

Message: 3 of 4

"Louis" <tanlouiss+matlab@gmail.com> wrote in message <hnknnm$mlh$1@fred.mathworks.com>...
> Hi,
>
> 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?
>
> Thanks
>
> 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


sum( repmat(A,p,1) .* ( reshape( repmat( reshape(B,1,p*n), m,1), m*p,n) ), 2)
that must work

Subject: Multiplying row of matrix by vector many times

From: Louis

Date: 15 Mar, 2010 19:23:10

Message: 4 of 4

Thanks for the help everyone, both solutions work fine.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com