fetchNext - Fetch next available unread output from
Simulink.Simulation.Future object array - MATLAB ([original](https://in.mathworks.com/help/simulink/slref/simulink.simulation.future.fetchnext.html)) ([raw](?raw))
Fetch next available unread output fromSimulink.Simulation.Future
object array
Syntax
Description
[[idx](#mw%5F1f7eb1cf-ef98-4ddd-8ce8-ffa3478f82e1),[simOut](#mw%5F4e5d3d3f-690e-475d-97da-5e6e280f0a6a)] = fetchNext([Future](#mw%5F306282b0-9aeb-48f5-86de-fe1c6822ad51))
waits for the unread element of Simulink.Simulation.Future
array,Future
, to reach a 'finished'
state. It returns the index of the simulation that finished, and the correspondingSimulink.SimulationOutput
object.
[[idx](#mw%5F1f7eb1cf-ef98-4ddd-8ce8-ffa3478f82e1),[simOut](#mw%5F4e5d3d3f-690e-475d-97da-5e6e280f0a6a)] = fetchNext([Future](#mw%5F306282b0-9aeb-48f5-86de-fe1c6822ad51), [Timeout](#mw%5F4d868746-1519-4487-9e4e-47d4be87ff1e))
waits for a maximum of Timeout
seconds for a result to become available. If the timeout expires before any result is available, simOut
is returned as an empty array.
An error is reported if there are no elements in Future
with propertyRead
as false. You can check for are any unread futures usinganyUnread = ~all([F.Read])
.
fetchNext
displays an error if any element ofFuture
with a 'finished'
state encounters an error during execution. The Read
property of that element becomestrue
allowing any subsequent call to fetchNext
to proceed.
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 onFuture
.
for i = 1:MuVal_length [completedIdx,simOut] = fetchNext(Future) end
Input Arguments
Array of Simulation.Simulink.Future
objects. To createFuture
, run parsim
with'RunInBackground'
option set to 'on'
.
Example: Future = parsim(in,'RunInBackground','on')
Specify a Timeout
for fetchNext
to retrieve the results from the Simulation.Simulink.Future
array,Future
.
Example: [idx, simOut] = fetchNext(Future, 45)
Output Arguments
When fetchNext
method is used on an array ofSimulink.Simulation.Future
objects, it returns the index of the simulation whose output is being retrieved.
Array of Simulink.SimulationOutput
objects that contain all of the logged simulation results. The size of the array is equal to the size of the array of Simulink.SimulationInput
objects.
All simulation outputs (logged time, states, and signals) are returned in a singleSimulink.SimulationOutput
object. You define the model time, states, and output that are logged using the Data Import/Export pane of the Model Configuration Parameters dialog box. You can log signals using blocks such as the To Workspace and Scope blocks. TheViewers & Generators Manager tool can directly log signals.
Version History
Introduced in R2017b