The result you observe could be because preallocation the second time appears to be faster than the first. So, timing each allocation separately I found a slightly different result (over 1000 runs)
clear all
tic
k=zeros([1,10000]);
toc;
tic;
a=1:10000;
k(a)=rand;
toc
tic
g=zeros([1,10000]);
toc;
tic;
for i=1:10000;
g(i)=rand;
end
toc
Elapsed time is 0.000250 seconds. % pre allocation 1
Elapsed time is 0.000238 seconds.
Elapsed time is 0.000035 seconds. % pre-allocation 2
Elapsed time is 0.000730 seconds.
Here, Vectorization appears to be faster, though, the difference is definitely pronounced when the array length is larger (10000000)
I would suggest going through the following answers and questions on vectorization:
Best Answer