Access Signal Logging Data

View Signal Logging Data

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.

Signal Logging Object

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.

View Logged Signal Data with the Simulation Data Inspector

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.

Programmatically Access Logged Signal Data Saved in Dataset Format

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.

Name

Description

get

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.

numElements

Get number of elements in the dataset.

For examples of accessing signal logging data that uses the Dataset format, see Simulink.SimulationData.Dataset.

Access Array of Buses Signal Logging Data

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:

  1. Use a Simulink.SimulationData.Dataset.get (or getElement) method to access a specific signal in the logged data (by default, the logsout variable).

  2. To get the values, index within the array of buses.

  3. Index again to get data for a specific bus.

For example, to obtain the signal logging data for the Constant6 block in the ex_log_nested_aobex_log_nested_aob model, for the topBus signal that feeds the Terminator block:

logsout.getElement('topBus').Values.a(2,2).firstConst.data

Below are additional examples of accessing array of buses signal logging data. For another example that shows how to log array of buses data, see sldemo_mdlref_bussldemo_mdlref_bus.

 Simple Array of Buses

 Array of Buses in a Bus

 Nested Arrays of Buses

Accessing Data for Signals with a Duplicate Name

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.

    1. In the model, right-click the signal.

    2. In the context menu, select Properties.

    3. In the Signal Properties dialog box, set Logging name to Custom and specify a different name than the signal name.

    4. Simulate the model and use the Simulink.SimulationData.Dataset.getElement method with a name argument.

Handling Newline Characters in Signal Logging Data

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:

topOut.getElement(sprintf('INCREMENT\nBUS'))

Handling Spaces and Newlines in Logged Names

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
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:

>> logsout.getElement(2)

Programmatically Access Logged Signal Data Saved in ModelDataLogs Format

    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.

Was this topic helpful?