% To run the examples in this section, create a nonscalar structure array with arrays of different sizes in field f1.
s(1).f1 = rand(3, 6);
s(2).f1 = magic(12);
s(3).f1 = ones(5, 10);
% Count the number of elements in each f1 field.
counts = arrayfun(@(x) numel(x.f1), s)
% The syntax @(x) creates an anonymous function. This code returns%
% counts =
% 18 144 50
% Compute the size of each array in the f1 fields.
[nrows, ncols] = arrayfun(@(x) size(x.f1), s)
% This code returns
%
% nrows =
% 3 12 5
% ncols =
% 6 12 10
% Compute the mean of each column in the f1 fields of s. Because the output is nonscalar, set UniformOutput to false.
averages = arrayfun(@(x) mean(x.f1), s, 'UniformOutput', false)
% This code returns
%<