%% Call afterAll on parfeval Computations
% You can use afterAll to automatically invoke functions on all of the combined outputs of your 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 among all of those vectors after they are created. afterAll executes the function handle on the combined output of all the futures when they all become ready.

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

% Copyright 2012 The MathWorks, Inc.