Random walk code - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Random walk code

Posts: 4Member
Hello, this is the Question:
Suppose you want to know how often a single source of fungus will spread more than one foot from a fallen tree. You will be using a computer simulation to answer the question.

i found this code using the m file ranwalk2d.m:

2-dimensional random walk
ranwalk2d.m

Plots the points (u(k),v(k)), k=1:n, in the (u,v)-plane, where (u(k)) and (v(k)) are one-dimensional random walks. The sample code plots four trajectories of the same walk, four different colors.

n=100000;
colorstr=['b' 'r' 'g' 'y'];
for k=1:4
z=2.*(rand(2,n)<0.5)-1;
x=[zeros(1,2); cumsum(z')];
col=colorstr(k);
plot(x(:,1),x(:,2),col);
hold on
end
grid

The problem is i don't want the graph to go below 0 on the y axis. In other words pertaining to the problem, the fungus cant go back to its starting point.

I'm not a computer science person so i'm not that knowledgeable. Can Someone please guide me on how to do random walks on matlab?