title: Remove Characters from EOF while Writing to File in Matlab
body: <p>In Matlab, after creating a certain number of lines and printing them to a file, I have the need to delete a line and rewrite the rest of the data to that same file.  When I do so, the new data overwrites the previous data, but since the data is shorter than the original, there are still remnants of the original data.  Does anyone have any idea what the best/most efficient way to delete that extra data is?</p>
  
  <p>Here is a simplified example of what I'm trying to do:</p>
  
  <pre><code>fid = fopen('file.txt','w');  
  for i=1:10  
      fprintf(fid,'%i\r\t',i);  
  end  
  frewind(fid);  
  for i=3:5  
      fprintf(fid,'%i\r\t',i);  
  end  
  fprintf(fid,'EOF');  
  fclose(fid);  
  </code></pre>
  
  <p>I've looked all over, but I can't seem to find the solution to my question.  Any suggestions?</p>