title: How to reach a boundary point as specified by user from origin , random walk simulation
body: <p>I am trying to create a function in MATLAB: </p>
  
  <p>It simulates a random walk and I want to count the number of steps it took to reach a boundary point as specified by user from origin (0,0)
  they will specify: (b,z)
  b: is the x point on the boundary it reaches in conjunction with
  z: as the y point on the boundary. </p>
  
  <p>Currently it is stopping after it reaches either the b or z value, but I want both to be reached. for example: I want it to reach (3,3) but it will stop running after it reaches (3,1) thus only satisfying one of my constraints. </p>
  
  <p>Any help will be greatly appreciated!</p>
  
  <p>Here is my code:</p>
  
  <pre><code>function s= rw_selectpoint(b,z)
  %%exit time for square
  
  %%set up square 2bx2z
  %%center of square =(0,0)
  x=0;
  y=0;
  
  walk_num=0;
  
  %%set up probabilities and loop 
  while (abs(x)&lt; b &amp;&amp; abs(y)&lt;z)
  
   r= rand();
  if (r&lt;=.25)
  walk_num=walk_num+1;
  x=x+1
  
  elseif ((.25&lt;r) &amp;&amp; (r&lt;=.5))
  walk_num=walk_num+1;
  x=x-1
  
  elseif ((.5&lt;r) &amp;&amp; (r&lt;=.75))
  walk_num=walk_num+1;
  y=y+1
  
  else %(.75&lt;r)    
  walk_num=walk_num+1;
  y=y-1
  end
  
  end
  s=walk_num;
  display (x)
  display (y)
  %display (s)
  end
  </code></pre>