title: MATLAB mean of cell array of multidimensional arrays
body: <p>I have a cell array called template, where template is a 1x29 cell array. Each cell of template is a 14x10x31 matrix. Each element of the matrix is a double.</p>
  
  <p>I want to find the mean 14x10x31 matrix of template i.e. I want a result which is a 14x10x31 matrix where e.g. element (1,1,1) of the result is the mean of all 29 values of (1,1,1) in the cell array template.</p>
  
  <p>I'm not clear how to go about this.</p>
  
  <p>I've looked at <code>cellfun</code>, and the options for the <code>mean</code> command i.e. how mean can be calculated across dimensions. For example, to calculate mean m across all three dimensions would be done as follows ...</p>
  
  <pre><code>m = cellfun(@(x) mean(mean(mean(x,1),2),3) , template, 'UniformOutput', false)
  </code></pre>
  
  <p>... which will give 1x29 cell array, each cell containing a single value i.e. the averaging together of all values in each 14x10x31 array, for each cell of the template variable.</p>
  
  <p>But obviously this isn't what I want.</p>
  
  <p>To achieve what I want do I need to convert (<code>cell2mat</code>?) the template variable to a matrix of 29x14x10x31 and then run <code>mean</code> on the first dimension of that? I've looked at <code>reshape</code> and <code>cat</code> too but I'm not clear how to put it all together though ... or if that is the best way to achieve what I want? Or can it / should it be done by using <code>cellfun</code>?</p>