Just write the code as usual. Almost all Matlab functions can accept and return vectorized input. For example, to simulate the Buryat movement of N particles in 1 dimension
position = zeros([N 1]); %start at origin
sigma = sqrt(D * dt); %D is diffusion coefficient, dt is time step
for j = 1:numSteps
position = position + sigma*randn(size(position));
end
, , , "dot times"
position = position + sigma.*randn(size(position));
, , .
function newstep = step(position)
%diffusion in a overdamped harmonic potential
newstep = -dt*k*position + D*randn(size(position));
for j = 1:numsteps; position = position + step(position);
..