Documentation Center

  • Trial Software
  • Product Updates

Access Signal Logging Data

View Signal Logging Data

To generate signal logging data, simulate the model. 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 with 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 signal logging 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, in the Simulink Editor, use one of the following approaches:

  • To display logged signals whenever a simulation ends or when you pause a simulation, select Simulation > Model Configuration Parameters > Inspect signals when simulation is stopped/paused.

  • To launch the Simulation Data Inspector tool to display the data immediately, 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 consists of a structure of MATLAB timeseries objects.

The Simulink.SimulationData.Dataset class provides two methods for accessing signal logging data.




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.

The ex_bus_loggingex_bus_logging model illustrates how to access signal logging data.

For additional 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. To access the signal logging data for an array of buses, navigate the bus hierarchy and specify the index of the bus element whose data you want to view.

The general approach is to use a Simulink.SimulationData.Dataset.get (or getElement) method with the logged data (by default, the logsout variable). Use the command (using an index into the array) to navigate from the array of buses down to a bus in the array of buses. Use the command to return data for a specific signal.

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

 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 signals 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. Simulink sorts the data for those signals based on the model hierarchy, in top-down order.

To access a specific signal that has a duplicate name, use one of these approaches:

  • Visually inspect the 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 following approach, if 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:


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.

When you use the ModelDataLogs signal logging format, Simulink saves the logging data in a Simulink.ModelDataLogs object. For information on extracting signal data from that object, see Simulink.ModelDataLogs. The Simulink.ModelDataLogs object contains signal data objects to capture signal logging information for specific model elements.

Model ElementSignal Data Object
Top-level or referenced modelSimulink.ModelDataLogs
Subsystem in a modelSimulink.SubsysDataLogs
Scope block in a modelSimulink.ScopeDataLogs
Signal other than a bus or Mux signalSimulink.Timeseries
Bus signal or Mux signalSimulink.TsArray

Virtual Signals

A virtual signal is a signal that graphically represents other signals or parts of other signals. Virtual signals have no functional or mathematical significance. For more information, see Virtual Signals.

The nonvirtual components of a virtual signal are called regions. A virtual signal can contain the same region more than once. For example, if the same nonvirtual signal is connected to two input ports of a block, the block outputs a virtual signal that has two regions.

When you use the ModelDataLogs signal logging format, the log of a virtual signal that contains duplicate regions includes all of the regions, even though the data in each is the same. Logged virtual signal regions appear in the log in a Simulink.TsputArray object. The log gives the duplicate regions unique names, using the syntax: <signal_name>_reg<#counter>.

Bus Signals

You can log bus signals. When you use ModelDataLogs signal logging format, Simulink stores each logged bus signal data in a separate Simulink.TsArray object.

The hierarchy of a bus signal is preserved in the logged signal data. The logged name of a signal in a virtual bus derives from the name of the source signal. The logged name of a signal in a nonvirtual bus derives from the applicable bus object, and can differ from the name of the source signal. See Composite Signals for information about those capabilities.

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:

  • ModelDataLogs for the signal logging format

  • The default of logsout for the signal logging data

logsout =
Simulink.ModelDataLogs (model_name):
  Name                   Elements  Simulink Class

  ('x y')                   1      Timeseries
b')                   1      Timeseries
Wave1')         1      Timeseries

You cannot access any of the Simulink.Timeseries objects in this log using TAB name completion or by typing the name to MATLAB. This syntax is not recognized because the space or newline in each name appears to the MATLAB parser as a separator between identifiers. For example:

>> logsout.x y

??? logsout.x y
Error: Unexpected MATLAB expression.

To reference a Simulink.Timeseries object whose name contains a space, enclose the element containing the space in single quotes:

>> logsout.('x y')

          Name: 'x y'
     BlockPath: 'model_name/Sine'
     PortIndex: 1
    SignalName: 'x y'
    ParentName: 'x y'
      TimeInfo: [1x1 Simulink.TimeInfo]
          Time: [51x1 double]
          Data: [51x1 double]

To reference a Simulink.Timeseries object whose name contains a newline, concatenate to construct the element containing the newline:

>> cr=sprintf('\n')
>> logsout.(['a' cr 'b'])

The same techniques work when a space or newline in a data log derives from the name of:

  • An unnamed logged signal's originating block

  • A subsystem or Model block that contains any logged signal

  • Any block that is superior to such a block in the model hierarchy

This code can reference logged data for the signal:

>> logsout.(['SL_Sine' cr 'Wave1'])

For names with multiple spaces, newlines, or both, repeat and combine the two techniques as needed to specify the intended name to MATLAB.

    Note:   You cannot use these techniques for TAB name completion.

Was this topic helpful?