Main Content

Simulink.Simulation.Future class

Package:Simulink.Simulation
Superclasses:

CreateFutureobject for simulation

Description

创建一个Simulink.Simulation.Futureobject when you executeparsim'RunInBackground'argument set to'on'. Theparsimcommand runs multiple simulations in parallel using the inputs specified with an array ofSimulink.SimulationInputobjects. You can use this object to monitor the status of ongoing simulations, fetch outputs of completed simulations, or cancel ongoing simulations.

Theparsimcommand uses the Parallel Computing Toolbox™ license to run the simulations in parallel.parsimruns the simulations in serial if a parallel pool cannot be created or if Parallel Computing Toolbox is not used.

Construction

future= parsim(in,'RunInBackground','on')creates aSimulink.Simulation.Futureobject,future, while running multiple simulations in parallel using the inputs specified in theSimulink.SimulationInputobject,in.

Input Arguments

expand all

ASimulink.SimulationInputobject or an array ofSimulink.SimulationInputobjects is used to run multiple simulations. Specify parameters and values of a model to run multiple simulations without making it dirty.

Example:in = Simulink.SimulationInput('vdp'),in(1:10) = Simulink.SimulationInput('vdp')

Set to'on', to run simulations asynchronously, keeping the MATLAB®command prompt available.

Properties

expand all

Text log of outputs from the simulation.

This property is read-only.

ID of thefutureobject, specified as a scalar integer.

This property is read-only.

Whether a call tofetchNextorfetchOutputshas read the outputs in theSimulink.Simulation.Futureobject array, specified as 1 if true and 0 if false.

This property is read-only.

Current state offutureobject array, specified as'pending','queued','running',“完成”,'failed', or'unavailable'.

This property is read-only.

方法

Method

Purpose

取消

Cancel a pending, queued, or runningSimulink.Simulation.Futureobject

fetchNext

Fetch next available unread output fromSimulink.Simulation.Futureobject array

fetchOutputs

RetrieveSimulink.SimulationOutputfromSimulink.Simulation.Future

wait

Wait forSimulink.Simulation.Futureobjects to complete simulation

Examples

collapse all

This example shows how to create aSimulink.Simulation.Futureobject array and use it to retrieve outputs and see the status of simulations.

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

Open the model and define a vector of Mu values.

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

UsingMu_Values, initialize an array ofSimulink.SimulationInputobjects. To preallocate the array, a loop index is made to start from the largest value.

fori = MuVal_length:-1:1 in(i) = Simulink.SimulationInput('vdp'); in(i) = in(i).setBlockParameter('vdp/Mu',...“获得”,num2str(Mu_Values(i)));end

Simulate the model usingparsim. Set it to 'RunInBackground', to be able to use the command prompt, while simulations are running.

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

Use thefetchNextmethod onFuturesimulations.

fori = 1:MuVal_length [completedIdx,simOut] = fetchNext(Future)end

See Also

Functions

Classes

Introduced in R2018a