Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Pag Max
Posts:
13
Registered:
5/16/11


Re: Array multiplication by a vector
Posted:
Jan 17, 2012 5:06 AM


Thanks!! Both are pretty cool solutions. I did think repmat would be a way to go about it but was not sure. bsxfun is completely new to me. Thank you so much for showing that!!
Greg Heath <gheath01@gmail.com> wrote in message <8e26555b98f247249acb173bf94619b4@dp8g2000vbb.googlegroups.com>... > On Jan 17, 4:09 am, "Pag Max" <tismarkhanNOS...@gamil.com> wrote: > > I have a M X N array and 1 X N vector. I am looking for another array of size M X N such that each of the N column of the original array are multiplied or scaled by corresponding element in the vector. > > > > This can be done very easily witha loop but I want to know if there is a smarter way. > > > > example > > > > >> a=[1 2 3; 4 5 6]; > > >> b=[5 6 8]; > > >> for j=1:numel(b) > > > > c(:,j)=a(:,j)*b(j); > > end > > c = > > > > 5 12 24 > > 20 30 48 > > >> a.*repmat(b,size(a,1),1) > > ans = > > 5 12 24 > 20 30 48 > > Hope this helps > > Greg



