Why not just
>> 6:6:18 ans = 6 12 18
Or
>> 6*(1:3) ans = 6 12 18
Or using bsxfun:
>> sum(bsxfun(@times,1:3,(1:3).'),1) ans = 6 12 18
Or if you really want to use a loop (which is a waste of MATLAB):
>> V = zeros(1,3); >> for k = 1:numel(V), V(k)=sum(k*(1:3)); end >> V V = 6 12 18