View and Access Signal Logging Data
You can view logged signal data during simulation using the Simulation Data Inspector, or for paused or stopped simulations, using other visualization interfaces. See Decide How to Visualize Simulation Data.
Alternatively, you can access signal logging data programmatically, using MATLAB® commands.
Tip
If you do not see logging data for a signal that you marked in the model for signal logging, check the logging configuration. Use the Signal Logging Selector to enable logging for a signal whose logging is overridden. For details, see View the Signal Logging Configuration and Override Signal Logging Settings.
Signal Logging Object
The software saves signal logging data in a
Simulink.SimulationData.Dataset
object, which is a MATLAB workspace variable. The default name of the signal logging variable is
logsout
. You can change the variable name using the text box next to
the Signal logging parameter in the Configuration Parameters dialog
box.
You can specify whether you want the data for individual signals in a dataset to use
MATLAB
timeseries
or timetable
elements by setting the
Dataset signal format configuration parameter. For details, see Dataset signal format.
Releases earlier than R2016a also supported a ModelDataLogs
format.
For details, see Convert Data to Dataset Format.
To search for specific elements in a Dataset
object, use the find
function. To return the names of the Dataset
object
elements, use the getElementNames
function.
Tip
To call a function on each specified MATLAB
timeseries
object, you can use the Simulink.SimulationData.forEachTimeseries
function. For example, you can use
this function to make it easy to resample every element of a structure of
timeseries
objects obtained by logging a bus signal.
Access Data Programmatically
Access a Simulink.SimulationData.Dataset
object and its elements.
Simulate the model sldemo_clutch
, which models a rotating clutch system. Then, access the Dataset
object sldemo_clutch_output
, which contains the signal logging data. For more information about the model, see Building a Clutch Lock-Up Model.
sim("sldemo_clutch");
sldemo_clutch_output
sldemo_clutch_output = Simulink.SimulationData.Dataset 'sldemo_clutch_output' with 10 elements Name BlockPath ____________ _________________________________ 1 [1x1 Signal] Fn sldemo_clutch/Clutch Pedal 2 [1x1 Signal] Tin sldemo_clutch/Engine Torque 3 [1x1 Signal] LockedFlag sldemo_clutch/Friction Mode Logic 4 [1x1 Signal] LockupFlag sldemo_clutch/Friction Mode Logic 5 [1x1 Signal] UnlockFlag sldemo_clutch/Friction Mode Logic 6 [1x1 Signal] Tfmaxk sldemo_clutch/Friction Model 7 [1x1 Signal] Tfmaxs sldemo_clutch/Friction Model 8 [1x1 Signal] ShaftSpeed sldemo_clutch/Locked 9 [1x1 Signal] EngineSpeed sldemo_clutch/Unlocked 10 [1x1 Signal] VehicleSpeed sldemo_clutch/Unlocked - Use braces { } to access, modify, or add elements using index.
To access Dataset
object elements, you can use indexing with curly braces. For example, access the Tin
element of the signal logging Dataset
object using the index 2
.
el2 = sldemo_clutch_output{2}
el2 = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'Tin' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [1x1 timeseries] Methods, Superclasses
The signal data is stored in the Values
property of the Simulink.SimulationData.Signal
object as a timeseries
object. The time values are in the Time
property of the timeseries
object. The signal values are in the Data
property.
el2.Values
timeseries Common Properties: Name: 'Tin' Time: [387x1 double] TimeInfo: tsdata.timemetadata Data: [387x1 double] DataInfo: tsdata.datametadata
Handling Spaces and Newlines in Logged Names
This example shows three signals that illustrate how signal logging names:
A signal with a name that contains a space
A signal with a name that contains a newline
An unnamed signal that originates on a block with a name that contains a newline
Simulate the model and then look at the signal logging results in the
logsout
variable. You can see that the names in the
Dataset
object use a space where the signal name contained a space and a
newline where the name contained a newline. The unnamed signal has an empty character array
as its name.
logsout
logsout = Simulink.SimulationData.Dataset 'logsout' with 3 elements Name BlockPath ____ ______________________________________ 1 [1x1 Signal] x y ex_signal_names_with_spaces/Sine Wave 2 [1x1 Signal] a b ex_signal_names_with_spaces/Sine Wave1 3 [1x1 Signal] '' ex_signal_names_with_spaces/Sine Wave2 - Use braces { } to access, modify, or add elements using index.
You can access a signal with a name that contains a space by name or by index. Include
the space in the name you pass to the getElement
function. To access a
signal with a name that contains a newline, use the index.
>> logsout{2}
ans = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'a↵b' PropagatedName: '' BlockPath: [1×1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [1×1 timeseries]
Access Logged Signal Data in ModelDataLogs
Format
Before R2016a, you could log signals in ModelDataLogs
format.
Starting in R2016a, you cannot log data in the ModelDataLogs
format.
Signal logging uses the Dataset
format.
If you have already logged signal data in the ModelDataLogs
format, you can use the convertToDataset
function to update the
signal logging data to use Dataset
format. For more information, see
Migrate Legacy Code That Uses ModelDataLogs.
See Also
get
| find
| getElementNames
| numElements
| setElement
| Simulink.SimulationData.Dataset
| Simulink.SimulationData.Signal
| Simulink.SimulationData.BlockPath
| Simulink.SimulationData.forEachTimeseries