title: How to fprintf column headers in MATLAB?
body: <p>I have two matrices A and B as given below:</p>
  
  <pre><code>A = [1
       2
       3
       4
       5]
  
  B = [10  11  12  13
       15  16  17  18
       17  12  15  13
       20  21  22  17
       40  41  32  33]
  </code></pre>
  
  <p>and I would like to output it to a text file in the form given below with column headers as shown:</p>
  
  <p><strong>Desired text output</strong></p>
  
  <pre><code>A  B   B   B   B
  1  10  11  12  13
  2  15  16  17  18
  3  17  12  15  13
  4  20  21  22  17
  5  40  41  32  33
  </code></pre>
  
  <p><strong>Reproducible code</strong></p>
  
  <pre><code>A = [1; 2; 3; 4; 5];
  B = [10, 11, 12, 13;
       15, 16, 17, 18;
       17, 12, 15, 13;
       20, 21, 22, 17;
       40, 41, 32, 33;];
  
  ALL = [A B];
  
  ALL_cell = mat2cell(ALL, ones(size(ALL,1),1), size(ALL,2));
  
  fID = fopen('output.dat','w');
  f = @(x) fprintf(fID,'%s\n',sprintf('%f\t',x));
  cellfun(f,ALL_cell);
  fclose(fID);
  </code></pre>
  
  <p>How to insert the column headers as shown above with MATLAB? Sometimes, the columns in B could be over 100, as an example I have given only 4.</p>