Main Content

fetchNext

Fetch next available unread output from Simulink.Simulation.Future object array

Description

[idx,simOut] = fetchNext(Future) 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 corresponding Simulink.SimulationOutput object.

[idx,simOut] = fetchNext(Future, Timeout) 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 property Read as false. You can check for are any unread futures using anyUnread = ~all([F.Read]).

fetchNext displays an error if any element of Future with a 'finished' state encounters an error during execution. The Read property of that element becomes true allowing any subsequent call to fetchNext to proceed.

Examples

collapse all

This example shows how to create a Simulink.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.

open_system('vdp');
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',...
        '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.

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

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

Specify a Timeout for fetchNext to retrieve the results from the Simulation.Simulink.Future array, Future.

Example: [idx, simOut] = fetchNext(Future, 45)

Output Arguments

collapse all

When fetchNext method is used on an array of Simulink.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 single Simulink.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. The Viewers & Generators Manager tool can directly log signals.

Version History

Introduced in R2017b

See Also

Functions

Classes