title: Finding pixels containing 0
body: <p>I'm trying to calculate the pixels within a range. I calculated the range, but I can't count the pixels containing 0.</p>
  <p>My code:</p>
  <pre><code>first_value_of_i = zeros(M,1);
  first_value_of_j = zeros(N,1);
  
  second_value_of_i = zeros(M,1);
  second_value_of_j =zeros(N,1);
      
  for i = 2:M-1       
      for j = 2:N-1
                      
          Pix = [image(i,j) image(i-1,j) image(i-1,j+1) image(i,j+1) image(i+1,j+1) image(i+1,j) image(i+1,j-1) image(i,j-1) image(i-1,j-1) image(i-1,j)];
           
          if((Pix(1)==0) &amp;&amp; ( (Pix(2)*Pix(3)*Pix(4)*Pix(5)*Pix(6)==0) || (Pix(2)*Pix(6)*Pix(7)*Pix(8)*Pix(9)==0)))
              
              if (((Pix(2)+Pix(6)+Pix(7)+Pix(8)+Pix(9))&gt;=5) || ((Pix(2)+Pix(3)+Pix(4)+Pix(5)+Pix(6))&gt;=5))             
                  first_value_of_i(i,1) = i;
                  first_value_of_j(j,1) = j;
              end
              
              if (((Pix(2)+Pix(3)+Pix(4)+Pix(8)+Pix(9))&gt;=5) || ((Pix(4)+Pix(5)+Pix(6)+Pix(7)+Pix(8))&gt;=5))             
                  second_value_of_i(i,1) = i;
                  second_value_of_j(j,1) = j;
              end               
              
          end % if
          
      end %for
          
  end %for
      
  rest_stroke = zeros(M,2);
  
  for p = first_value_of_i : second_value_of_i
      
      count_rest=0;
      
      for q = first_value_of_j:second_value_of_j                      
          if((image(p,q)==0))
              count_rest=count_rest+1;
          end        
      end
                  
      rest_stroke(i,1)=i;
      rest_stroke(i,2)=count_rest; 
  end
   
  </code></pre>
  <p>But the output shows:</p>
  <blockquote>
  <p>Subscript indices must either be real positive integers or logicals.</p>
  <p>Error in trying (line 173)<br />
  if((image(p,q)==0))</p>
  </blockquote>
  <p>According to my calculation it should be ok, but evidently, it is not. Can anyone help me out?</p>