title: Looping in Matlab to batch process Excel files
body: <p>I know how to read in multiple Excel files, but am struggling to conduct the same analysis on all of those files. The analysis requires I average some values in different columns, then print those average values to a separate Excel sheet. I can do this with one Excel file, but have trouble figuring out how to print each average value in a different row in the output Excel file. Here is the code I have that works for one file (reads it, averages values in column 4, then prints to a separate Excel file):</p>
  
  <pre><code> data = xlsread('test_1.xlsx');
   average_values_1 = data(:,4);
   a = [average_values_1];
   data_cells = num2cell(a);
   column_header ={'Average Value 1'};
   row_header(1,1) ={'File 1'}
   output = [{' '} column_header; row_header data_cells];
   xlswrite('Test Averages.xls', output);
  </code></pre>
  
  <p>How might I do this over and over again while printing values from each file in the output file as its own table? I suspect a nested loop is in my future. </p>
  
  <p>Thanks in advance. </p>