%% Return Scalar Structure
% Create a scalar structure with fields that contain matrices.

S.f1 = 1:10;
S.f2 = [2 3; 4 5; 6 7];
S.f3 = rand(4,4)

%
% Calculate the means of each matrix. mean returns vectors containing the mean of each column, so the means cannot be returned as an array. To return the means in a structure, specify the 'UniformOutput',false name-value pair.

A = structfun(@mean,S,'UniformOutput',false)

% Copyright 2012 The MathWorks, Inc.