title: When and why should I use cellfun in Matlab?
body: <p>I have a question regarding the <code>cellfun</code> function in MATLAB.</p>
  
  <p>When / why should I use it, and when may I just as well drop it?</p>
  
  <p>A simple example: Let's say I have a cell <code>a</code>, and I want to find the average of all values in <code>a</code>.</p>
  
  <pre><code>a{1} = [1 2;3 4];
  a{2} = [1 2 3;4 5 6; 7 8 9];
  </code></pre>
  
  <p>My approach would be something like:</p>
  
  <pre><code>mean([a{1}(:); a{2}(:)])
  </code></pre>
  
  <p>What will the appropriate <code>cellfun</code> version of this be, and is it any better?</p>
  
  <p>I've tried doing something like this, (obviously not working):</p>
  
  <pre><code>mean_a = mean(cellfun(@mean, a,'UniformOutput',0))
  </code></pre>
  
  <p>Thanks!</p>