Documentation

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

View Data in Simulation Data Inspector

You can use the Simulation Data Inspector to view data for signals marked for logging.

  1. Open the model.

  2. Select Simulation > Output > Send Logged Workspace Data to Data Inspector.

  3. Select Simulation > Output > Simulation Data Inspector.

  4. Simulate the model.

For additional information about using the Simulation Data Inspector, see Inspect Signal Data with Simulation Data Inspector.

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.

Releases earlier than R2016a also supported a ModelDataLogs format. For details, see Migrate Scripts That Use 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 the get method. For example, you can access the first element of the topOut signal logging Dataset object using get with an index.

open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_mdlref_counter_bus')));
open_system(docpath(fullfile(docroot,'toolbox','simulink',...
'examples','ex_bus_logging')));
sim('ex_bus_logging')
topOut
topOut = 

  Simulink.SimulationData.Dataset
  Package: Simulink.SimulationData

  Characteristics:
              Name: 'topOut'
    Total Elements: 4

  Elements:
    1: 'COUNTERBUS'
    2: 'OUTPUTBUS'
    3: 'INCREMENTBUS'
    4: 'inner_bus'

  -Use get or getElement to access elements by index, name or 
   block path.
  -Use addElement or setElement to add or modify elements.

  Methods, Superclasses
element1 = topOut.get(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.

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

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 Examples

Was this topic helpful?