title: Matlab: select a portion of a matrix
body: <p>The following script gives me the error "Subscript indices must either be real positive integers or logicals."</p>
  
  <p>I do not understand why, since the vars are integers. Moreover, I also cast them to integers.</p>
  
  <p>The code is:</p>
  
  <pre><code>x_start = int16(x-matrixRay);
          x_end = uint16(x+matrixRay);
          y_start = uint16(y-matrixRay);
          y_end = uint16(y+matrixRay);
          matrix = img(x_start:x_end,y_start:y_end);
  </code></pre>
  
  <p>I put a breakpoint just before the code above. Below I list the values of the variables:</p>
  
  <pre><code>    K&gt;&gt; x_start
  
  x_start =
  
    uint16
  
     298
  
  K&gt;&gt; x_end
  
  x_end =
  
    uint16
  
     302
  
  K&gt;&gt; y_start
  
  y_start =
  
    uint16
  
     88
  
  K&gt;&gt; y_end
  
  y_end =
  
    uint16
  
     92
  
  K&gt;&gt; matrixRay
  
  matrixRay =
  
       2
  </code></pre>
  
  <p>Clearly I cannot post all the matrix "img", since it is pretty big. The workspace it is a 1369x1173 uint8.</p>