title: Create a separate log file for each iteration in a for loop
body: <p>I just want to make a script which runs multiple files and stores their outputs in separate log files. </p>
  
  <p>So I wrote the code by using <code>diary</code> to generate the output, but the <code>diary</code> function is only 1 log file and the output is updating in the same log file for remaining iterations. In my <code>testconfig_1</code> file, I have at present only print as the content.</p>
  
  <p>Then I tried to use the <code>fopen</code> method, with this I am getting multiple log files but I don't understand how I can put that data into the log file which I have created through <code>fopen</code> after each run.</p>
  
  <pre><code>% with diary method
  clear all;
  diary on;
  instring ='testconfig_';
  for x = 1:3 
  fprintf ('Simulation on testconfig_%d \n' , x);
  test = [instring num2str(x)];
  run(test);
  diary testconfig_(x).log;
  end
  
  % without diary method
  clear all;
  diary on;
  instring ='testconfig_';
  for x = 1:3
  fprintf ('Simulation on testconfig_%d \n', x);
  test = [instring num2str(x)];
  run(test);
  fid = fopen(sprintf('testconfig_%d.log',x),'w');
  end
  </code></pre>
  
  <p>I wanted to get <code>testconfig_1.log</code>, <code>testconfig_2.log</code>, <code>testconfig_3.log</code> and I wanted to print <code>in_testconfig_1</code>, <code>in_testconfig_2</code>, <code>in_testconfig_3</code> respectively</p>