title: Modify the value of a specific position in a text file in Matlab
body: <pre><code>AIR, ID
  
  AIR.SIT
  
    50   1   1   1   0   0   2   1
  
     43.57 -116.24      1.   857.7 
  </code></pre>
  
  <p>Hi, All,</p>
  
  <p>I have a text file like above. Now in Matlab, I want to create 5000 text files, changing the number "2" (the specific number in the 3rd row) from 1 to 5000 in each file, while keeping other contents the same. In every loop, the changed number is the same with the loop number. And the output in every loop is saved into a new text file, with the name like AIR_LoopNumber.SIT. </p>
  
  <p>I've spent some time writing on that. But it is kind of difficult for a newby. Here is what I have:</p>
  
  <pre><code> % - Read source file.
  
   fid = fopen ('Air.SIT');
  
   n = 1;
  
   textline={};
  
   while (~feof(fid))
       textline(n,1)={fgetl(fid)};     
   end
  
   FileName=Air;
  
  
   % - Replace characters when relevant.
  
   for i = 1 : 5000
  
      filename = sprintf('%s_%d.SIT','filename',i);
  
  
   end
  </code></pre>
  
  <p>Anybody can help on finishing the program?</p>
  
  <p>Thanks,
  James</p>