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, as described in this topic.
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.
Simulink® 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. For details, see Specify a Name for Signal Logging Data.
You can specify whether you want the data for individual signals in a dataset to use
MATLAB
timeseries
or timetable
elements. Set the
Dataset signal format configuration parameter (for details, see Dataset signal format).
Releases earlier than R2016a also supported a ModelDataLogs
format.
For details, see Migrate Scripts That Use Legacy ModelDataLogs API.
You can use the Simulink.SimulationData.Dataset
API to access signal
logging data programmatically. To access Dataset
object elements, use
indexing with curly braces. For example, you can access the first element of the
topOut
signal logging Dataset
object using index
1
. This example is based on the use of the default setting of
timeseries
for the dataset elements. For details about
timeseries
and timetable
format data, see Dataset signal format.
open_system(docpath(fullfile(docroot,'toolbox','simulink',... 'examples','ex_bus_logging'))); open_system(docpath(fullfile(docroot,'toolbox','simulink',... 'examples','ex_mdlref_counter_bus'))); sim('ex_bus_logging') topOut
Simulink.SimulationData.Dataset 'topOut' with 4 elements Name BlockPath ____________ ________________________________________ 1 [1x1 Signal] COUNTERBUS ex_bus_logging/COUNTERBUSCreator 2 [1x1 Signal] OUTPUTBUS ex_bus_logging/CounterA 3 [1x1 Signal] INCREMENTBUS ex_bus_logging/IncrementBusCreator 4 [1x1 Signal] inner_bus ...erA|ex_mdlref_counter_bus/Bus Creator - Use braces { } to access, modify, or add elements using index.
element1 = topOut{1}
element1 = Simulink.SimulationData.Signal Package: Simulink.SimulationData Properties: Name: 'COUNTERBUS' PropagatedName: '' BlockPath: [1x1 Simulink.SimulationData.BlockPath] PortType: 'outport' PortIndex: 1 Values: [1x1 struct] Methods, Superclasses
element1.Values
ans = data: [1x1 timeseries] limits: [1x1 struct]
To search for specific elements in a Dataset
object, use the
find
method. To return the names of the Dataset
object elements, use the getNames
method.
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.
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. You just
need to 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]
ModelDataLogs
FormatBefore 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.
However, you can use data that was logged in a previous release using
ModelDataLogs
format.
For more information, see
. Simulink.ModelDataLogs
find
| get
| getElementNames
| numElements
| setElement
| Simulink.SimulationData.BlockPath
| Simulink.SimulationData.Dataset
| Simulink.SimulationData.forEachTimeseries
| Simulink.SimulationData.Signal