Main Content


Fetch the partial simulation output during simulation run time

Since R2022a


simOut = simulink.compiler.getSimulationOutput('modelName') fetches the simulation output while the deployed simulation is executing.


collapse all

This example code shows how to use the simulink.compiler.getSimulationOutput function to get the Simulink.SimulationOutput while the deployed simulation is executing.

Create the Simulink.SimulationInput object for the model.

in = Simulink.SimulationInput(model);

Set model parameters for the model.

in = in.setModelParameter('SimulationMode', 'Rapid');
in = in.setModelParameter('SaveOutput', 'on');
in = in.setModelParameter('SaveFormat', 'Dataset');
in = in.setModelParameter('StopTime', 'Inf');

Configure the mode and time for the simulation.

tmr = timer('Name','PartialSimOut','ExecutionMode','singleShot','StartDelay', 30);
tmr.TimerFcn = @(~,~) partialSimOutFcn(test, model);
% Start and run the simulation for 30 seconds
% Simulate
out = sim(in);

Function to get a partial simulation output.

function u = partialSimOutFcn(test, model)
     % Get the sim output after the first 30 seconds of sim
     simOut = simulink.compiler.getSimulationOutput(model);
     % Stop the simulation

Input Arguments

collapse all

Model name that is simulated in the deployed simulation, specified as a character vector.

Example: 'vdp'

Output Arguments

collapse all

Output returned as the Simulink.SimulationOutput object. The returned output is partial with empty metadata.

Version History

Introduced in R2022a