title: dlmwrite appends to the end
body: <p>I am writing several lines to a text file, among which is a matrix. I decided to use fprintf for the normal text messages and to use dlmwrite for writing the matrix to the file. However, this action is done in a while loop. Here is the outline:</p>
  
  <pre><code> k=0;
  
   while (k&lt;10):
  
       fprintf(file,'%s', 'Hello');
  
       dlmwrite(file,M ,'-append', 'newline', 'pc');
  
       fprintf(file, '%s' , 'Goodbye');
  
       k= K+1;
  </code></pre>
  
  <p>however, when I open the file, all the matrices are appended to the very end of the text file instead of each being between a hello and a goodbye. Is there a way to fix this issue? </p>