Main Content


Wait for Simulink.Simulation.Future objects to complete simulation



Ok = wait(Future) blocks the command prompt until each element of the Simulink.Simulation.Future array, Future is in a 'finished' state.


collapse all

This example shows how to use the wait method on an array of future objects.

This example runs several simulations of the vdp model, varying the value of the gain Mu.

Open the model and define a vector of Mu values.

Mu_Values = [0.5:0.25:5];
MuVal_length = length(Mu_Values);

Using Mu_Values, initialize an array of Simulink.SimulationInput objects. To preallocate the array, a loop index is made to start from the largest value.

for i = MuVal_length:-1:1
    in(i) = Simulink.SimulationInput('vdp');
    in(i) = in(i).setBlockParameter('vdp/Mu',...

Simulate the model using parsim. Set to 'RunInBackground' to enable the use of command prompt while the simulations are running and to create an array of Simulink.Simulation.Future objects.

Future = parsim(in,'RunInBackground','on');

Use the wait method on Future to block the execution.

Ok = wait(Future)

Input Arguments

collapse all

Array of Simulation.Simulink.Future objects. To create Future, run parsim with 'RunInBackground' option set to 'on'.

Example: Future = parsim(in,'RunInBackground','on')

Output Arguments

collapse all

Ok is true if the wait completes successfully, false if any of the Future objects failed execution or were canceled. Specified as 1 if true, 0 if false.

Version History

Introduced in R2017b

See Also