From: Juliette Salexa on
Hello,
Say I had the matrix:

M= [A B ;
C D ]

and the vector:

V = [a ;
b ]

What would be the easiest way to get:

P=[Aa Ba;
Cb Db]


I am currently doing:

P(:,1)=M(:,1).*V
P(:,2)=M(:,2).*V


The only way I can think of generalizing this to larger dimensions would be using loops.

Is there simpler way, that would work even if M was 10 rows and 10 columns, and V was 10 columns ?

Thank you.
From: Matt Fig on
P = bsxfun(@times,M,V)
From: Juliette Salexa on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hpil5c$fal$1(a)fred.mathworks.com>...
> P = bsxfun(@times,M,V)

Perfect, thanks!
From: Juliette Salexa on
Anyone know why it's called bsx ?
From: Matt Fig on
Did you happen to look at the help? The help is always a good place to start.
 |  Next  |  Last
Pages: 1 2 3
Prev: Debug commands greyed out
Next: Sum of a cell