title: How can I get a waitbar to work in Matlab?
body: <p>I want to have a waitbar for an operation that takes quite a while. Here is my code:</p>
  
  <pre><code>h = waitbar(0,'Please wait...');
  
  for i=1:counterend
      waitbar(i/waitbarcounter)
      Atemp    = At+i*step;
      handle   = @(M) 1/M^2*((2/(gamma+1))*(1+(gamma-1)*M^2/2))^((gamma+1)/(gamma-1))-(Atemp/At)^2;
      Mach     = fzero(handle, 5);
      Aplot(i) =  Atemp/At;
      Tplot(i) = Tc / (1+(gamma-1)*Mach^2/2);
      Mplot(i) = Mach;
      plot(Aplot, Tplot)
  end
  
  close(h) 
  </code></pre>
  
  <p>The error Matlab gives is:</p>
  
  <blockquote>
    <p>??? Error using ==> waitbar at 249<br>
    Improper arguments for waitbar</p>
  </blockquote>
  
  <p>After investigation, I am sure that this error must occur because of the sorrounding code in the loop.</p>
  
  <p><em>Note: The loop works fine without the waitbar.</em></p>