title: Why is my for loop running over? (Matlab)
body: <p>I have the following code: </p>
  
  <pre><code>for i = 1:RGB_size(2) % RGB_size(2) = 1296 //X coords
  
      for j = 1:1:RGB_size(1) % RGB_size(1) = 964  //Y coords
  
          if mask(i,j) == 1
          data(next_pixel,:) = [ImgIndex, ImgTake, i, j, RGB(i,j,1), RGB(i,j,2), RGB(i,j,3),... 
              HSIR(i,j,1), HSIR(i,j,2), HSIR(i,j,3)];
  
          next_pixel = next_pixel + 1; %get next pixel
          end
      end
  end
  </code></pre>
  
  <p>But Matlab won't run my code because it says I'm trying to access <code>mask(965,1)</code> and my variable mask size is 1296&times;964. However, I don't see how this is possible. Any thoughts?</p>
  
  <p><code>RGB_size</code> is calculated from a variable called <code>RGB</code>, which is the same variable used to create the variable <code>mask</code>. I have verified that they are both the same size with the debugger.</p>
  
  <p>Actual error message is:</p>
  
  <blockquote>
    <p><code>Attempted to access mask(965,1); index out of bounds because size(mask)=[964,1296].</code></p>
  </blockquote>