%% Call afterEach on parfeval Computations
% You can use afterEach to automatically invoke functions on each of the results of parfeval computations.
% Use parfeval to compute random vectors in the workers. With default preferences, parfeval creates a parpool automatically if there is not one already created.

for idx = 1:10
    f(idx) = parfeval(@rand, 1, 1000, 1);
end

% Display the maximum element in each of those vectors after they are created. afterEach executes the function handle on the output of each future when they become ready.

afterEach(f, @(r) disp(max(r)), 0);

% Copyright 2012 The MathWorks, Inc.