get - Access simulation results in Simulink.SimulationOutput
object - MATLAB ([original](https://www.mathworks.com/help/simulink/slref/simulink.simulationoutput.get.html)) ([raw](?raw))
Main Content
Access simulation results in Simulink.SimulationOutput
object
Syntax
Description
[res](#bsgwba8-Value) = get([simOut](#mw%5F32072e73-3c48-4a4e-9bbb-c8cd2a23ad4c),[varName](#mw%5Fe4347cf2-1c48-44c1-ad9d-524db217b50b))
returns the simulation data specified by varName
from theSimulink.SimulationOutput
object simOut
.
You can also access data inside a Simulink.SimulationOutput
object using dot notation.
Examples
When you simulate a model in a way that returns simulation results as a single object, you access all logged data and simulation metadata using the Simulink.SimulationOutput
object.
The model in this example has the Single simulation output parameter enabled and logs data using several different logging methods.
- The output of the Sine Wave block is logged using signal logging.
- The output of the Gain block is logged using a To Workspace block.
- The outputs of the Gain, Chirp Signal, and Square Wave Generator blocks are logged using a Record block.
- The output of the Square Wave Generator block is logged using output logging.
The model is also configured to log time data.
Open the model.
mdl = "LoggingBlocks"; open_system(mdl)
Create a Simulink.SimulationInput
object to configure the simulation for the model. Use the setModelParameter
function to set the StopTime
parameter to 20
.
simin = Simulink.SimulationInput(mdl); simin = setModelParameter(simin,StopTime="20");
Simulate the model. The sim
function returns results as a Simulink.SimulationOutput
object that contains all data logged from the simulation. The data for each block and each type of logging is stored as a property that matches the name of the logging variable specified in the block or model.
You can access logged data using dot notation, the get
function, or the find
function.
Use dot notation to access the signal Big Sine
, which was logged using the To Workspace block.
timeseries
Common Properties: Name: 'Big Sine' Time: [51x1 double] TimeInfo: [1x1 tsdata.timemetadata] Data: [51x1 double] DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
Use the get
function to access the signal Sine
, which was logged using signal logging.
logsout = get(out,"logsout")
logsout = Simulink.SimulationData.Dataset 'logsout' with 1 element
Name BlockPath
____ _______________________
1 [1x1 Signal] Sine LoggingBlocks/Sine Wave
- Use braces { } to access, modify, or add elements using index.
Use the find
function to access the signal Square Wave
, which was logged using output logging.
yout = Simulink.SimulationData.Dataset 'yout' with 1 element
Name BlockPath
___________ _____________________
1 [1x1 Signal] Square Wave LoggingBlocks/Outport
- Use braces { } to access, modify, or add elements using index.
Access the simulation metadata in the SimulationMetadata
property of the SimulationOutput
object.
simmetadata = out.SimulationMetadata
simmetadata = SimulationMetadata with properties:
ModelInfo: [1×1 struct]
TimingInfo: [1×1 struct]
ExecutionInfo: [1×1 struct]
UserString: ''
UserData: []
The simulation metadata is returned as a Simulink.SimulationMetadata
object. The SimulationMetadata
object groups information as structures in the object properties.
View the ExecutionInfo
property on the SimulationMetadata
object. The execution information shows that the simulation ran through its stop time of 20
without warnings or errors.
simmetadata.ExecutionInfo
ans = struct with fields: StopEvent: 'ReachedStopTime' StopEventSource: [] StopEventDescription: 'Reached stop time of 20' ErrorDiagnostic: [] WarningDiagnostics: [0×1 struct]
Input Arguments
Simulation data to return, specified as a string or a character vector.
Use the get
function to access data logged from simulation, such as signal logging data, logged outputs, and states, by specifying the name of the logging variable. For example, when you use the default signal logging variable namelogsout
, specify "logsout"
to access the signal logging data.
Example: "logsout"
Data Types: char
| string
Output Arguments
Version History
Introduced in R2010a
Prior to R2020a, the get
function returned empty ([]
) if the specified Simulink.SimulationOutput
object did not have the specified property. Since R2020a, the get
function has issued a warning and returned empty ([]
) in this situation. Starting in R2023a, the get
function issues an error and no longer returns an output argument.
To query whether a Simulink.SimulationOutput
object has a given property, use the find function. Thefind
function returns empty ([]
) and does not issue a diagnostic when the object does not have the property.
The get
function issues a warning and returns empty ([]
) if the specified Simulink.SimulationOutput
object does not have the specified property.