Prev: Debug commands greyed out
Next: Sum of a cell
From: Juliette Salexa on 7 Apr 2010 15:03 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 7 Apr 2010 15:07 P = bsxfun(@times,M,V)
From: Juliette Salexa on 7 Apr 2010 15:12 "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 7 Apr 2010 15:17 Anyone know why it's called bsx ?
From: Matt Fig on 7 Apr 2010 15:20
Did you happen to look at the help? The help is always a good place to start. |