title: imwrite error during looping in matlab
body: <p>Im newbie in Matlab and I have a problem to saving my processed images.
  So here is the command to do segmentation, cropping my images and save it in the specific path</p>
  
  <p>Run.m</p>
  
  <pre><code>   Images_Number_Train=length(Input_Images);
     Urutan=1;
     for loop1=1:Images_Number_Train
     Images=imread(Input_Images(loop1));
     Label_Images=Label_Train(loop1);
     Sign = Crop_Sign(Images);
     Order= Save_Crop(Sign,Label_Images,Urutan);
     Urutan=Order;
     end
  </code></pre>
  
  <p>Save function</p>
  
  <pre><code>   function Urutan = Save_Crop(Sign,Label_Images,Urutan)
  
     Output_Path = 'E:\Images\Crop\Train\';
     if ~exist(Output_Path, 'dir')
     mkdir(Output_Training_Path);
     end
     newimagename = [Output_Path 'Images_Crop_' num2str(Urutan) '.pgm'];
     imwrite(Sign,newimagename);
     Urutan=Urutan+1;
     end
  </code></pre>
  
  <p>I have 120 Images and everytime I run the command, This program only can read images until 30 and then stop..</p>
  
  <p>I got this error messege:</p>
  
  <pre><code>      Error using imwrite (line 421)
        Expected DATA to be nonempty.
  
        Error in Save_Crop (line 24)
        imwrite(Sign,newimagename);
  </code></pre>
  
  <p>and the value of Sign variable will be (after images 30th)</p>
  
  <pre><code> val =
  
     Empty array: 0-by-0-by-3
  </code></pre>
  
  <p>Any suggestion, what I have to do</p>