MATLAB: Vectorize a loop with product and sum operations

bsxfunrepmatvectorize loop @times @sum

Hi all,
I come with a question about vectorization. Suppose I have to run a code equivalent to the following
x = 1:4;
v = rand(1,10);
for i = 1:length(x)
k(i,:) = x(i)*v + x(i)
end
when you have a combined product and sum operations for each iteration.
Basic solution I can come up with is the following:
k = bsxfun(@times,x',v) + repmat(x',1,6); k = x'*v + repmat(x',1,6); % equivalent to before
Does this make any sense in terms of true vectorization? Which is the best way to vector the code? I guess for this case there is a specific "easy" answer while in some other cases more careful mathematical analysis of the formulas should be performed in order to get a "smart" vectorization.
Any comment and answer is more than welcome

Best Answer

Francesco, use
bsxfun(@plus, x'*v, x')