Main Content

cancel

Cancel a pending, queued, or running Simulink.Simulation.Future object

Description

cancel(Future) stops the objects of the Simulink.Simulation.Future array, Future, that are currently in 'pending', 'queued', or 'running' state. For elements of the Futures in the 'finished' state, no action is taken.

example

Examples

collapse all

This example shows how to use the cancel method on an array of future objects to stop the simulations.

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.

openExample('simulink_general/VanDerPolOscillatorExample');
open_system('vdp');
Mu_Values = [0.5:0.25:1000];
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',...
        'Gain',num2str(Mu_Values(i)));
end

Simulate the model using parsim. Set to 'RunInBackground' to enable the use the command prompt, while simulations are running.

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

Now, assume that you want to run simulations with different values of Mu and cancel the ongoing simulations.

cancel(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')

Version History

Introduced in R2018a

See Also

Functions

Classes