Documentation

Simulink.SimulationMetadata class

Package: Simulink
Superclasses:

Access metadata of simulation runs

Description

The SimulationMetadata class contains information about a simulation run including:

  • Model information

  • Timing information

  • Execution and diagnostic information

  • Custom character vector to tag the simulation

  • Custom data to describe the simulation

SimulationMetadata packages this information with the SimulationOutput object. To use SimulationMetadata, use one of these approaches:

  • In Configuration Parameters > Data Import/Export, under Save options, select Single simulation output.

  • Use set_param to set ReturnWorkspaceOutputs to on.

    set_param(model_name,'ReturnWorkspaceOutputs','on');

To retrieve the SimulationMetadata object, use the getSimulationMetadata method on a SimulationOutput object.

Properties

expand all

The ModelInfo structure has these fields.

Field NameTypeDescription
ModelNamecharName of the model
ModelVersioncharVersion of the model
ModelFilePathcharAbsolute location of the .mdl/.slx file
UserIDcharSystem user ID of the machine used for the simulation
MachineNamecharHostname of the machine used for the simulation
PlatformcharOperating system of the machine used for the simulation
ModelStructuralChecksum4–by–1 uint32Structural checksum of the model calculated after an update diagram
SimulationModecharSimulation mode
StartTimedoubleSimulation start time
StopTimedoubleTime at which the simulation was terminated
SolverInfostructureSolver information:
  • Fixed-step solvers – Solver type, name, and fixed step size

  • Variable solvers – Solver type, name, and max step size (initial setting)

SimulinkVersionstructureVersion of Simulink®
LoggingInfostructureMetadata about logging to persistent storage:
  • LoggingToFile field — Indicates whether logging to persistent storage is enabled ('on' or 'off')

  • LoggingFileName field — Specifies the resolved file name for the persistent storage MAT-file (if LoggingToFile is 'on').

Structure to store information about a simulation run, including the reason a simulation stopped and any diagnostics reported during the simulation. The structure has these fields.

Field NameTypeDescription
StopEventNontranslated character vectorReason the simulation stopped, represented by one of these.
  • ReachedStopTime – Simulation stopped upon reaching stop time and no errors were reported during execution. StopEvent has value ReachedStopTime, even if errors are reported in the stop callbacks, which are executed after the simulation ends.

  • ModelStop – Simulation stopped by a block or by solver before reaching stop time

  • StopCommand – Simulation stopped manually by clicking the Stop button or programmatically using the set_param command

  • DiagnosticError – Simulation stopped because an error was reported during simulation

  • KeyboardControlC – Simulation stopped using keystroke Ctrl+C.

  • PauseCommand – Simulation paused manually by clicking the Pause button or programmatically using the set_param command

  • ConditionalPause – Simulation paused using a conditional breakpoint

  • PauseTime – Simulation paused at or after specified pause time

  • StepForward – Simulation paused after clicking step forward

  • StepBackward – Simulation paused after clicking step backward

  • TimeOut – Simulation stopped because execution time exceeded timeout specified by TimeOut

StopEventSourceSimulink.SimulationData.BlockPathSource of stop event, if it is a valid Simulink object
StopEventDescriptionTranslated character vectorSuper set of information stored in StopEvent and StopEventSource
ErrorDiagnosticstructError reported during simulation, represented by these fields.
  • DiagnosticMSLDiagnostic object that includes object paths, ID, message, cause, and stack

  • SimulationPhase – Represented by one of these: Initialization, Execution, or Termination

  • SimulationTime – Simulation time represented as a double, if reported during Execution; else, represented as []

By passing the name–value pair 'ReturnErrorsInOutput', 'on' to the sim command, errors generated during simulation are reported in ExecutionInfo.ErrorDiagnostic. The sim command does not capture generated errors.

WarningDiagnosticsArray of structArray of all warnings reported during the simulation. Each array item is represented by these fields.
  • DiagnosticMSLDiagnostic object that includes object paths, ID, message, cause, and stack

  • SimulationPhase – Represented by one of these: Initialization, Execution, or Termination

  • SimulationTime – Simulation time represented as a double, if reported during Execution; else, represented as []

Structure to store profiling information about the simulation, including the time stamps for the start and end of the simulation. The structure has these fields.

Field NameTypeDescription
WallClockTimestampStartcharacter vectorWall clock time when the simulation started, in YYYY-MM-DD HH:MI:SS format with microsecond resolution
WallClockTimestampStopcharacter vectorWall clock time when the simulation stopped, in YYYY-MM-DD HH:MI:SS format with microsecond resolution
InitializationElapsedWallTimedoubleTime spent before execution, in seconds
ExecutionElapsedWallTimedoubleTime spent during execution, in seconds
TerminationElapsedWallTimedoubleTime spent after execution in, seconds
TotalElapsedWallTimedoubleTotal time spent in initialization, execution, and termination, in seconds

The ExecutionElapsedWallTime includes the time that Simulink spent to roll back or step back in a simulation. The ExecutionElapsedWallTime does not include the time spent between steps. For example, if you use Stepper to step through a simulation, the ExecutionElapsedWallTime time does not include the time when the simulation is in a paused state. For more information about using Stepper, see How Simulation Stepper Helps With Model Analysis.

Use Simulink.SimulationOutput.setUserString to directly store a character vector in the SimulationMetadata object that is contained in the SimulationOutput object.

Use Simulink.SimulationOutput.setUserData to store custom data in the SimulationMetadata object that is contained in the SimulationOutput object.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).

Examples

expand all

Simulate the vdp model. Retrieve metadata from a SimulationMetadata object of the simulation.

Simulate the vdp model. Save the results of the Simulink.SimulationOutput object in simout.

 open_system('vdp');
 simout = sim(bdroot,'ReturnWorkspaceOutputs','on');

Retrieve metadata information about this simulation using mData. This is the SimulationMetadata object that simout contains.

 mData=simout.getSimulationMetadata()
mData = 

  SimulationMetadata with properties:

        ModelInfo: [1x1 struct]
       TimingInfo: [1x1 struct]
    ExecutionInfo: [1x1 struct]
       UserString: ''
         UserData: []

Store custom data or string in simout.

 simout=simout.setUserData(struct('param1','value1','param2','value2','param3','value3'));
 simout=simout.setUserString('Store first simulation results');

Retrieve the custom data you stored from mData.

 mData=simout.getSimulationMetadata()
 disp(mData.UserData)
mData = 

  SimulationMetadata with properties:

        ModelInfo: [1x1 struct]
       TimingInfo: [1x1 struct]
    ExecutionInfo: [1x1 struct]
       UserString: 'Store first simulation results'
         UserData: [1x1 struct]

    param1: 'value1'
    param2: 'value2'
    param3: 'value3'

Retrieve the custom string you stored from mData.

 mData=simout.getSimulationMetadata()
 disp(mData.UserString)
mData = 

  SimulationMetadata with properties:

        ModelInfo: [1x1 struct]
       TimingInfo: [1x1 struct]
    ExecutionInfo: [1x1 struct]
       UserString: 'Store first simulation results'
         UserData: [1x1 struct]

Store first simulation results

Introduced in R2015a

Was this topic helpful?