%% Apply Function that Returns Scalar From Vector
% Compute the mean of each variable in a 5-by-2 table.
% Define a table containing numeric variables.

A = table([0.71;-2.05;-0.35;-0.82;1.57],[0.23;0.12;-0.18;0.23;0.41])

%
% Define the anonymous function to find the mean of an input.

func = @mean;

%
% func uses an existing MATLAB® function to define the operation.
% Apply the function to all the variables of table A.

B = varfun(func,A)

% B is a table containing the average value from each variable. To return a numeric vector instead of a table, you can use B = varfun(func,A,'OutputFormat','uniform').
% Copyright 2012 The MathWorks, Inc.