title: Saving into variable file names using MATLAB
body: <p>I have a lot of images that are in a directory named 1.jpg, 2.jpg, 3.jpg etc. I read them one by one. I do some operation &amp; then I save them. </p>
  
  <p>I want to automate this operation. I can read the image names. Then while generating the output file I extract the image_name from the input file name, add my required extension names, add the type of file I want to save and then save the images by print command. </p>
  
  <pre><code>%//Read the image
  imagefiles = dir('*.bmp');      
  nfiles = length(imagefiles);    % Number of files found
  for ii=1:nfiles
      currentfilename = imagefiles(ii).name;
      currentimage = imread(currentfilename);
      images{ii} = currentimage;
      Img=currentimage;
  
      %//Do some operation on the image
  
      %//Save the image file
      h=figure;
      %//Display the figure to be saved  
      token = strtok(currentfilename, '.');
      str1 =  strcat(token,'_op');
      print(h,'-djpeg',str1);
  end
  </code></pre>
  
  <p>This program works fine but then I found out about this command to plot beautiful graphs. <a href="http://www.mathworks.in/matlabcentral/fileexchange/23629-exportfig" rel="nofollow"><code>export_fig</code></a></p>
  
  <p><code>export_fig</code> takes the basic command in the form of: </p>
  
  <pre><code>export_fig file_name.file_type
  </code></pre>
  
  <p>How can I substitute my output file name that is stored as str1 in place of file_name place-holder in the export_fig command automatically. </p>
  
  <p>NOTE: Please note this from the export_fig documentation (for variable file names)</p>
  
  <pre><code>for a = 1:5
  plot(rand(5, 2));
  export_fig(sprintf('plot%d.png', a));
  end
  </code></pre>
  
  <p>I do not want this solution. Please understand my query that there are thousands of MATLAB functions that requires data to be inputted as given in <code>export_fig</code> basic statement. The special case regarding variable file names have been already built within the export_fig function. </p>
  
  <p>I want to know if it was not built, then how could I have used automatically generated variable file names? My query is not specifically regarding export_fig but regarding the basic way in which I can supply variable file names if the input cannot be a string?</p>
  
  <p>Please ask me if you have trouble understanding the question. </p>