# MATLAB: I am trying to simulate a biased 2d random walk in a 100 x 100 unit domain and I can’t get the particles to walk one at a time and stick once they have either reached the bottom row or an occupied square.

2d random walk

The particles need to start in a nominated position along the top row of the domain and follow a biased walk (moving south, east or west) towards the bottom of the domain. Once they have reached the bottom or an occupied square they need to stick and then the next particle can start its walk. I need to use true and false (0's and 1's) to update the array position to occupied however I am not sure how to code this. Can anyone help? This is my code so far :
% Initialisation
N = 1 ; % Number of particles
M = 100; % Number of steps to take
Dx = 1; % Size of the jumps
Dy = 1;
%% Probability Case 1
x = zeros(M+1, N); % set all x positions to zero initially
y = zeros(M+1, N); % set all y positions to zero initially
% Simulation
for i = 1:M % for each M steps
``    r = rand(1,N);         % generate a random number between 0 and 1    west = r < 0.333;                  % mask finding west moving particles     x(i+1, west) = x(i, west) - Dx;    % move those particles west    y(i+1, west) = y(i, west);     east = r >= 0.333 & r < 0.667;     % mask finding east-moving particles    x(i+1, east) = x(i, east) + Dx;    % move those particles east    y(i+1, east) = y(i, east);     south = r >= 0.5 & r < 0.75;      % mask finding south-moving particles    x(i+1, south) = x(i, south);       y(i+1, south) = y(i, south) - Dy;  % move those particles south``
end
set(figure, 'Visible', 'on')
for n = 1:i+1
``    plot(x(n,:), y(n,:), '.', 'MarkerSize', 20)    xlabel('Position x_n');    ylabel('Position y_n');    axis equal    axis([-L, L, -L, L ]);    title(['Step number = ', num2str(n)]);    drawnowend``