%% Return Outputs in Cell Array
% Create a nonscalar structure array. Each structure has a field that contains numeric matrices.

S(1).f1 = rand(3,5);
S(2).f1 = rand(6,10);
S(3).f1 = rand(4,2)

% Calculate the mean for each field in S by using the arrayfun function. mean returns vectors containing the mean of each column, so the means cannot be returned as an array. To return the means in a cell array, specify the 'UniformOutput',false name-value pair.

A = arrayfun(@(x) mean(x.f1),S,'UniformOutput',false)

% Copyright 2012 The MathWorks, Inc.