title: Preallocating arrays in Matlab?
body: <p>I am using a simple <code>for</code> loop to crop a large amount of images and then storing them in a cell array. I keep getting the message:</p>
  
  <blockquote>
    <p>The variable <code>croppedSag</code> appears to change size on every loop iteration. Consider preallocating for speed.</p>
  </blockquote>
  
  <p>I have seen this several times before while coding in MATLAB. I have always ignored it and am curious how much preallocating will increase the runtime if I have, say, 10,000 images or a larger number?</p>
  
  <p>Also, I have read about preallocating in the documentation and it says to use <code>zeros()</code> for that purpose. How would I use that for the code below? </p>
  
  <pre><code>croppedSag = {};
  for i = 1:sagNum
      croppedSag{end+1} = imcrop(SagArray{i},rect);
  end
  </code></pre>
  
  <p>I didn't quite follow the examples in the documentation.</p>