title: How to create a random path between two known points in matrix in MATLAB
body: <p>If there is a matrix and two known points, how to create one random path (no need to be the shortest) between these two points with:</p>
  
  <ol>
  <li>a path that can have a level of deviation</li>
  <li>a path can be totally random (but not necessary)</li>
  <li>the next step can be only from 4 neighbors</li>
  </ol>
  
  <p>ex.
  5x5 matrix with two known points: <code>(2,1)</code> and <code>(5,5)</code></p>
  
  <p>After input: <code>pt1 = [2,1]; pt2 = [5,5];</code>.</p>
  
  <p>How could I get the pattern such as follows with the path recorded in the parameter, such as<code>path = [2,1;2,2-;3,2;4,2;4,3;4,4;4,5;5,5]</code>.</p>
  
  <pre><code>X X X X X
  
  o o X X X
  
  X o X X X
  
  X o o o o
  
  X X X X o
  </code></pre>