title: Get the indexes of the boundary cells of a subset of a matrix. Matlab
body: <p>Given a matrix where 1 is the current subset</p>
  
  <pre><code>test =
  
       0     0     0     0     0     0
       0     0     0     0     0     0
       0     0     1     1     0     0
       0     0     1     1     0     0
       0     0     0     0     0     0
       0     0     0     0     0     0
  </code></pre>
  
  <p>Is there a function, or quick method to get change the subset to the boundary of the current subset?</p>
  
  <p>Eg. Get this subset from 'test' above</p>
  
  <pre><code>test =
  
       0     0     0     0     0     0
       0     1     1     1     1     0
       0     1     0     0     1     0
       0     1     0     0     1     0
       0     1     1     1     1     0
       0     0     0     0     0     0
  </code></pre>
  
  <p>In the end I just want to get the minimum of the cells surrounding a subset of a matrix. Sure I could loop through and get the minimum of the boundary (cell by cell), but there must be a way to do it with the method i've shown above.</p>
  
  <p>Note the subset WILL be connected, but may not be rectangular. This may be the big catch.</p>
  
  <p>This is a possible subset.... (Would pad this with a NaN border)</p>
  
  <pre><code>test =
  
       0     0     0     0     0     0
       0     0     0     0     0     0
       0     0     1     1     0     0
       0     0     1     1     0     0
       0     0     1     1     1     1
       0     0     1     1     1     1
  </code></pre>
  
  <p>Ideas?</p>