Varian in matlab applies multiple functions to input
<p>I've understood the use of varfun in matlab. I need to apply <code>mean</code> and <code>std</code> to the grouped variables of this table.  </p>

<pre><code>N     mut    time
___    ___    ____

250    0.1    0.07
250    0.1    0.05
250    0.1    0.04
250    0.1    0.03
250    0.2    0.03
250    0.2    0.04
250    0.2    0.03
250    0.2    0.05
250    0.3    0.05
250    0.3    0.06
750    0.2    0.24
750    0.3    0.29
750    0.3     0.3
750    0.3    0.31
750    0.3     0.3
750    0.4    0.33
750    0.4    0.34
750    0.4    0.33
750    0.4    0.32
750    0.5    0.38
750    0.5    0.39
</code></pre>

<p>This table has two values of <code>N</code> and five different values of <code>mut</code> and I need to compute the average of <code>time</code> grouped by <code>N</code> and <code>mut</code>.
To do this I use the <code>varfun</code> function with the function handle <code>@mean</code></p>

<pre><code>Tgroup = varfun(@mean,T,'InputVariables','time','GroupingVariables',{'N','mut'})
</code></pre>

<p>and I get:</p>

<pre><code>mut     N     GroupCount    mean_time
___    ___    __________    _________

0.1    250    4             0.0475   
0.2    250    4             0.0375   
0.2    750    1               0.24   
0.3    250    2              0.055   
0.3    750    4                0.3   
0.4    750    4               0.33   
0.5    750    2              0.385  
</code></pre>

<p>but now I also want to add a column that contains the standard deviation. To do this I create a anonymous function</p>

<pre><code>func = @(x)[mean(x), std(x)]
</code></pre>

<p>and I use it in <code>varfunc</code></p>

<pre><code>varfun(@(x)[mean(x),std(x)],([T(1:5:50,:);T(400:5:450,:)]),'InputVariables','time','GroupingVariables',{'mut','N'})
</code></pre>

<p>Unfortunately I get this:</p>

<p>ans = </p>

<pre><code>mut     N     GroupCount         Fun_time      
___    ___    __________    ___________________

0.1    250    4             0.0475     0.017078
0.2    250    4             0.0375    0.0095743
0.2    750    1               0.24            0
0.3    250    2              0.055    0.0070711
0.3    750    4                0.3     0.008165
0.4    750    4               0.33     0.008165
0.5    750    2              0.385    0.0070711
</code></pre>

<p>where the last column 'Fun_time' contains two sub columns, the first being the mean of grouped times, the second the standard deviation of grouped times.</p>

<p>How can I split these two columns directly using an anonymous function? This is very similar to what is done in R with the <code>plyr</code> package.</p>