title: Open text files in matlab and save them from matlab
body: <p>I have a big text file containing data that needs to be extracted and inserted into a new text file. I possibly need to store this data in an cell/matrix array ?</p>
  
  <p>But for now, the question is that I am trying to test a smaller dataset, to check if the code below works.</p>
  
  <p>I have a code in which it opens a text file, scans through it and replicates the data and saves it in another text file called, "output.txt". </p>
  
  <p>Problem : It doesn't seem to save the file properly. It just shows an empty array in the text file, such as this <code>" [] "</code>. The original text file just contains string of characters.</p>
  
  <pre><code>%opens the text file and checks it line by line.
  fid1 = fopen('sample.txt');
  tline = fgetl(fid1);
  while ischar(tline)
      disp(tline);
      tline = fgetl(fid1);
  end
  fclose(fid1);
  
  
  % save the sample.txt file to a new text fie
  fid = fopen('output.txt', 'w');
  fprintf(fid, '%s %s\n', fid1);
  fclose(fid);
  
  % view the contents of the file
  type exp.txt
  </code></pre>
  
  <p>Where do i go from here ?</p>