Main Content


Retrieve an array of Simulink.SimulationOutput objects from all simulations in Simulink.Simulation.Job

Since R2018b



out = fetchOutputs(simJob) returns an array of Simulink.SimulationOutput objects containing the results of the simulations in a batch job, simJob.

fetchOutputs reports an error if the job is not in the 'finished' state, or if one of its simulations encounters an error during execution. Use the wait method to wait for the job to complete before fetching outputs.


collapse all

This example shows how to run parallel simulations in batch and fetch the resulting Simulink.SimulationOutput objects from the Simulink.Simulation.Job object. batchsim command offloads simulations to the compute cluster, enabling you to carry out other tasks while the batch job is processing, or close the client MATLAB® and access the batch job later.

1. Open the model.


2. Define a set of values for different temperatures.

setPointValues = 65:2:85;
spv_Length = length(setPointValues);

3. Using setPointValues, initialize an array of Simulink.SimulationInput objects.

in(1:spv_Length) = Simulink.SimulationInput('sldemo_househeat');
for i = 1:1:spv_Length 
    in(i) = in(i).setBlockParameter('sldemo_househeat/Set Point',...

4. Specify the pool size of the number of workers to use. In addition to the number of workers used to run simulations in parallel, a head worker is required. In this case, assume that three workers are available to run a batch job for the parallel simulations. The job object returns useful metadata as shown. You can use the job ID to access the job object later from any machine. NumWorkers displays how many workers are running the simulations – the number of workers specified in the 'Pool' argument plus an additional head worker.

simJob = batchsim(in,'Pool',3)
                  ID: 1
                Type: pool
          NumWorkers: 4
            Username: #####
               State: running
      SubmitDateTime: ##-###-#### ##:##:##
    Running Duration: 0 days 0h 0m 0s

5. Access the results of the batch job using the fetchOutputs method. fetchOutputs returns an array of Simulink.SimulationOuput objects. You can fetch outputs only once simJob is in finished state.

out = fetchOutputs(simJob)
1x11 Simulink.SimulationOutput array

Input Arguments

collapse all

A Simulink.Simulation.Job object. To create simJob, run batchsim.

Example: simJob = batchsim(in,'Pool',4)

Output Arguments

collapse all

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 passed to batchsim.

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 Signal & Scope Manager tool can directly log signals.

Version History

Introduced in R2018b