%% Run Functions in Background
% This example shows how to run a function in the background using parfeval and backgroundPool. When you run a function in the background, you can run other MATLAB code at the same time.
%
% Use parfeval to run the function magic(3) and retrieve one output. Specify backgroundPool as the first argument to run the function in the background. When you use parfeval, you create a Future object.

f = parfeval(backgroundPool,@magic,1,3);

%
% To retrieve the output from the background, use fetchOutputs. MATLAB returns the output once the execution of magic is complete.

fetchOutputs(f)

% Copyright 2021 The MathWorks, Inc.