MATLAB: Element wise multiplication and sum

matrix manipulation

hi,
i have a matirx a = [1,2,3;4,5,6]; and another matrix b=[2,2,2]
i want to multiply a[i,:].*b where i=1,2 (i.e. the rows of matrix a).
this will result in a matrix y with two rows (with 15 in row1 and 30 in row2)
how do i achieve this efficently without writing a "for" loop.
thanks in advance

Best Answer

I don't know where the 15 came from. I assume you mean 12.
>> a = [1,2,3;4,5,6];
>> b = [2,2,2];
>> a*b.' % same results as: sum(a.*[b;b],2)
ans =
12
30