Simulink.Simulation.Future - Create Future object for simulation - MATLAB (original) (raw)
Namespace: Simulink.Simulation
Superclasses: ``
Create Future
object for simulation
Description
Create a Simulink.Simulation.Future
object when you execute parsim with the 'RunInBackground'
argument set to'on'
. The parsim
command runs multiple simulations in parallel using the inputs specified with an array of Simulink.SimulationInput objects. You can use this object to monitor the status of ongoing simulations, fetch outputs of completed simulations, or cancel ongoing simulations.
The parsim
command uses the Parallel Computing Toolbox™ license to run the simulations in parallel. parsim
runs the simulations in serial if a parallel pool cannot be created or if Parallel Computing Toolbox is not used.
Construction
`future` = parsim([in](#mw%5Fc4c6d93d-5757-4e3b-aed3-5de732ca4d68),['RunInBackground'](#mw%5F2f281fe7-3de0-4919-9ad2-4995a0f23824),'on')
creates a Simulink.Simulation.Future
object, future
, while running multiple simulations in parallel using the inputs specified in the Simulink.SimulationInput
object, in
.
Input Arguments
A Simulink.SimulationInput
object or an array ofSimulink.SimulationInput
objects 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
Text log of outputs from the simulation.
This property is read-only.
ID of the future
object, specified as a scalar integer.
This property is read-only.
Whether a call to fetchNext
or fetchOutputs
has read the outputs in the Simulink.Simulation.Future
object array, specified as 1 if true and 0 if false.
This property is read-only.
Current state of future
object array, specified as'pending'
, 'queued'
,'running'
,'finished'
,'failed'
, or'unavailable'
.
This property is read-only.
Methods
Method | Purpose |
---|---|
cancel | Cancel a pending, queued, or runningSimulink.Simulation.Future object |
fetchNext | Fetch next available unread output fromSimulink.Simulation.Future object array |
fetchOutputs | Retrieve Simulink.SimulationOutput fromSimulink.Simulation.Future |
wait | Wait for Simulink.Simulation.Future objects to complete simulation |
Examples
This example shows how to create aSimulink.Simulation.Future
object array and use it to retrieve outputs and see the status of 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:5]; MuVal_length = length(Mu_Values);
Using Mu_Values
, initialize an array ofSimulink.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 it to 'RunInBackground
', to be able to use the command prompt, while simulations are running.
Future = parsim(in,'RunInBackground','on');
Use the fetchNext
method on Future
simulations.
for i = 1:MuVal_length [completedIdx,simOut] = fetchNext(Future) end
Version History
Introduced in R2018a