title: how to check in matlab if a 3D array has at least one non zero element?
body: <p>I tried to check if a 3D array is not all zeros using the next code:</p>
  
  <pre><code>notAll_n0_GreaterThan_ni=1;
  
  while notAll_n0_GreaterThan_ni 
      notAll_n0_GreaterThan_ni=0;        
      mask=(n0&lt;ni);
      numDimensions=ndims(mask);
      for dim_ind=1:numDimensions
          if any(mask,dim_ind) 
              notAll_n0_GreaterThan_ni=1;
              break;
          end
      end   
      if notAll_n0_GreaterThan_ni 
          n0(mask)=n0(mask)+1;
      end
  end
  </code></pre>
  
  <p>It seems I have error in the code because at the end I get for example:       n_0(11,3,69)=21 while ni(11,3,69)=21.1556.
  I can't find the error. I'll appreciate if someone shows me where I'm wrong and also if there is a simpler way to check existence of nonzero elements in a 3D array.  </p>