|On this page…|
You can view the signal logging data for a paused or completed simulation, using one of these interfaces:
The Simulation Data Inspector
Programmatically, using MATLAB® commands
To access signal logging data programmatically, the approach you use depends on the signal logging data format (Dataset or ModelDataLogs). For details, see:
Note: If you do not see logging data for a signal that you marked in the model for signal logging, check the logging configuration using the Signal Logging Selector. 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 signal logging object, which you access using a MATLAB workspace variable.
The type of the signal logging object depends on the signal logging format that you choose. For details, see Specify the Signal Logging Data Format.
Dataset format — Uses a Simulink.SimulationData.Dataset object
ModelDataLogs format — Uses a Simulink.ModelDataLogs object
The default name of the signal logging variable is logsout. You can change the variable name. For details, see Specify a Name for the Signal Logging Data for a Model.
You can use the Simulation Data Inspector to view logged signal data.
To view logged signal data with the Simulation Data Inspector, open the Simulink Editor and use one of the following approaches:
To display logged signals when a simulation ends or when you pause a simulation, select Simulation > Output > Send Logged Workspace Data to Data Inspector.
To launch the Simulation Data Inspector to display the logged data, select Simulation > Output > Simulation Data Inspector.
For additional information about using the Simulation Data Inspector, see Inspect Signal Data with Simulation Data Inspector.
When you use the default Dataset signal logging format, Simulink saves the logging data in a Simulink.SimulationData.Dataset object. For information about extracting signal data from that object, see the Simulink.SimulationData.Dataset reference page.
The Simulink.SimulationData.Dataset object contains a Simulink.SimulationData.Signal object for each logged signal.
For bus signals, the Simulink.SimulationData.Signal object contains a structure of MATLAB timeseries objects.
The Simulink.SimulationData.Dataset class provides two methods for accessing the signal logging data and its associated information.
You can also use the getElement method, which shares the same syntax and behavior as the get method.
Get element or collection of elements from the dataset, based on index, name, or block path.
Get number of elements in the dataset.
For examples of accessing signal logging data that uses the Dataset format, see Simulink.SimulationData.Dataset.
Signal logging data for an array of buses uses Dataset signal logging format.
The general approach to access data for a specific signal in an array of buses is:
Use a Simulink.SimulationData.Dataset.get (or getElement) method to access a specific signal in the logged data (by default, the logsout variable).
To get the values, index within the array of buses.
Index again to get data for a specific bus.
For a model with multiple signals that have the same signal name, the signal logging data includes a Simulink.SimulationData.Signal object for each signal that has a duplicate name.
To access a specific signal that has a duplicate name, use one of these approaches:
Visually inspect the displayed output of Simulink.SimulationData.Signal objects to find the data for the specific signal.
Use the Simulink.SimulationData.Dataset.getElement method, specifying the blockpath for the source block of the signal.
Create a script to iterate through the signals with a duplicate signal name, using the Simulink.SimulationData.Dataset.getElement method with an index argument.
Use the Signal Properties dialog box to specify a different name. Consider using this approach when the signals with a duplicate name do not appear in multiple instances of a referenced model in Normal mode.
In the model, right-click the signal.
In the context menu, select Properties.
In the Signal Properties dialog box, set Logging name to Custom and specify a different name than the signal name.
Simulate the model and use the Simulink.SimulationData.Dataset.getElement method with a name argument.
Tip Alternatively, you can use the Signal Logging Selector to access a specific signal. For details, see Override Signal Logging Settings with the Signal Logging Selector.
To handle newline characters in logging names in signal logging data that uses Dataset format, use a sprintf command within a getElement call. For example:
Signal names in data logs can have spaces or newlines in their names when:
The signal is named and the name includes a space or newline character.
The signal is unnamed and originates in a block whose name includes a space or newline character.
The signal exists in a subsystem or referenced model, and the name of the subsystem, Model block, or of any superior block, includes a space or newline character.
The following three examples show a signal whose name contains a space, a signal whose name contains a newline, and an unnamed signal that originates in a block whose name contains a newline:
The following example shows how to handle spaces or new lines in logged names, if a model uses:
Dataset for the signal logging format
The default of logsout for the signal logging data
logsout = Simulink.SimulationData.Dataset Package: Simulink.SimulationData Characteristics: Name: 'logsout' Total Elements: 3 Elements: 1: '' 2: 'x y' 3: 'a b'
To access a signal with a space or newline, use the index. For example, to access the x y signal:
Note: The ModelDataLogs signal logging format is supported for backward compatibility. For new models, use the Dataset format.
For information on extracting signal data from that object, see Simulink.ModelDataLogs.