title: Matlab saving cell array to text file
body: <p>After searching mathworks' website and here too I managed to find the code that is SUPPOSED to work for saving cell data to a text file... but every variation I found doesn't work. Here's my current code (and the one that has appeared the most here and on mathworks) - please help me figure out why it's not working for me...:</p>
  
  <p><strong>first attempt:</strong></p>
  
  <pre><code>array = cell(1,10);
  for i=1:10
      array{i} = 'someText';
  end
  fid = fopen('file.txt', 'wt');
  fprintf(fid, '%s\n', array);
  fclose(fid);
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <p>Error using fprintf
  Function is not defined for 'cell' inputs.</p>
  
  <p>Error in saveToFile (line 11)
  fprintf(fid, '%s\n', array);</p>
  
  <p>So I specifically looked for one that is good for cell-arrays (can be found here: <a href="http://www.mathworks.com/help/matlab/import_export/write-to-delimited-data-files.html" rel="nofollow">http://www.mathworks.com/help/matlab/import_export/write-to-delimited-data-files.html</a>)</p>
  
  <p><strong>Second attempt:</strong></p>
  
  <pre><code>array = cell(1,10);
  for i=1:10
      array{i} = 'someText';
  end
  fileID = fopen('celldata.dat','w');
  [nrows,ncols] = size(array);
  for row = 1:nrows
  fprintf(fileID,'%s\n' ,array{row,:});
  end
  fclose(fileID);
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <p>Error using fprintf
  Function is not defined for 'cell' inputs.</p>
  
  <p>Error in saveToFile (line 12)
  fprintf(fileID,'%s\n' ,array{row,:});</p>
  
  <p>I will spare you some other failed attempts.. these were the best I could find.. Any help will be greatly appreciated! :)</p>