get
Access simulation results in Simulink.SimulationOutput
object
Description
Examples
Access Data in Simulink.SimulationOutput
Object
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 output out
is 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.
out = sim(simIn);
You can access logged data using dot notation, the get
function, or the find
function.
Use dot notation to access the Big Sine
signal logged using the To Workspace block.
simout = out.simout
timeseries Common Properties: Name: 'Big Sine' Time: [51x1 double] TimeInfo: tsdata.timemetadata Data: [51x1 double] DataInfo: tsdata.datametadata
Use the get
function to access the Sine
signal 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 Square Wave
signal logged using output logging.
yout = find(out,"yout")
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.
You can access the simulation metadata using dot notation or using the getSimulationMetadata
function.
simMetadata = getSimulationMetadata(out)
simMetadata = SimulationMetadata with properties: ModelInfo: [1x1 struct] TimingInfo: [1x1 struct] ExecutionInfo: [1x1 struct] UserString: '' UserData: []
The simulation metadata is returned as a Simulink.SimulationMetadata
object. The SimulationMetadata
object groups information about the simulation in properties with structure values and has properties that allow you to specify a string and additional data related to the simulation.
Access 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: [0x1 struct]
Input Arguments
simOut
— Simulation results
Simulink.SimulationOutput
object
Simulation results, specified as a Simulink.SimulationOutput
object.
varName
— Simulation data to return
string | character vector
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 name
logsout
, specify "logsout"
to access the signal
logging data.
Example: "logsout"
Data Types: char
| string
Output Arguments
res
— Simulation results
Simulink.SimulationData.Dataset
object | timeseries
object |
timetable
| array | structure
Simulation results, returned in one of these forms:
timeseries
objectarray
structure
The form of the return argument depends on the type of data you access and the configuration of the model for the simulation.
Version History
Introduced in R2010aR2023a: Issues error if specified object does not have specified property
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. The
find
function returns empty ([]
) and does not
issue a diagnostic when the object does not have the property.
R2020a: Warns if specified object does not have specified property
The get
function issues a warning and returns empty
([]
) if the specified Simulink.SimulationOutput
object
does not have the specified property.
See Also
Objects
Simulink.SimulationOutput
|Simulink.SimulationData.Dataset
|timeseries
|timetable
|Simulink.op.ModelOperatingPoint
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)