MATLAB: Random walk problem.

for loophomeworkMATLABrandomrandom walk

I'm doing part 3 of this assignment. I got the thing to work. But i can't get the walker to bounce back. My for loop for that doesn't seem to work. Any advice?
iterations = 1;
Num_steps = 1000;
Random_steps_r = NaN(Num_steps,iterations);
for i = 1:iterations
Random_steps_r(:,i) = cumsum(-1 + 2 * round(rand(Num_steps,1)),1);
end
x=Random_steps_r;
if Random_steps_r>=10
x=9;
elseif Random_steps_r<=-10
x=-9;
end
comet(x)
The part that doesn't work is the last forloop.
thanks

Best Answer

This looks like homework and many people uploading homework problems edit them away after they've been answered. We will be sure to not to do majority of work (so you won't be cheating) if you promise not to delete the question after we help you.
Hint: Basically you might do something like
if x+deltaX > xMax
x = xMax - (x + deltaX - xMax); % Reflect about xMax
end