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 <email@example.com> wrote in message <firstname.lastname@example.org>... > 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