% Simulation of a discretized Wiener process 

T=1;
N=500;
dt=T/N;
W=zeros(1,N+1); % preallocation for efficiency reasons

for j=2:N+1
    W(j)=W(j-1)+sqrt(dt)*randn;
end

plot(0:dt:T,W)