Documentation

View and Access Signal Logging Data

You can view the signal logging 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.

Signal Logging Object

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.

Access Data Programmatically

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.

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 (or any parent block) whose name includes a space or newline character.

The following three examples show signals whose names contain:

  • A space

  • A signal whose name contains a newline

  • 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 when a model uses the default of logsout for the signal logging data.

logsout
Simulink.SimulationData.Dataset 'logsout' with 3 elements

                         Name  BlockPath            
                         ____  ____________________ 
    1  [1x1 Signal]      ''    untitled/Sine  Wave2
    2  [1x1 Signal]      x y   untitled/Sine Wave  
    3  [1x1 Signal]      x y   untitled/Sine Wave1 

  - Use braces { } to access, modify, or add elements using index.

To access a signal with a space or newline, use the index. For example, to access the x y signal:

>> logsout.getElement{2}
ans = 

  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'x  y'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1x1 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.

However, you can use data that was logged in a previous release using ModelDataLogs format.

For more information, see Simulink.ModelDataLogs.

See Also

| | | | | | | |

Related Topics

Was this topic helpful?