Main Content

Visualize and Access Signal Logging Data

You can use signal logging to save data from a simulation without adding blocks to your model. For more information, see Save Signal Data Using Signal Logging. When you use signal logging to save simulation data, the data is stored in the workspace and streamed to the Simulation Data Inspector.

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

Tip

If you do not see signal logging data for a signal that you marked in the model for signal logging, check the logging configuration to make sure that Signal logging is selected. Alternatively, 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.

For information about logging other types of data and different logging techniques, see Save Simulation Data.

View Signal Logging Data Using Simulation Data Inspector

To visually inspect and compare logged signal data interactively, consider using the Simulation Data Inspector. The Simulation Data Inspector allows you to view data from multiple simulations and sources on multiple subplots. You can zoom and pan within plots, use data cursors for close examination of signal values, and replay data to analyze signal relationships. For more information, see Inspect Simulation Data. You can also use the Simulation Data Inspector to compare data and metadata that you log in a simulation or import from the workspace or a file. Tailor comparisons to your needs by specifying signal properties, comparison constraints, and tolerances. See Compare Simulation Data.

Signal logging data is automatically streamed to the Simulation Data Inspector during simulation, so you can view and analyze data from models with infinite simulation time or real-time models during simulation. For more information, see View Streaming Data in the Simulation Data Inspector.

Access Workspace Data Programmatically

You can access and analyze data logged to the workspace programmatically. By default, all simulation data logged to the workspace is returned as a single Simulink.SimulationOutput object in a variable with the default name out. The SimulationOutput object contains complete simulation metadata and all simulation data logged to the workspace.

When you configure a model to return all simulation data in a single SimulationOutput object, signal logging data is stored as a property of the SimulationOutput object in a Simulink.SimulationData.Dataset object with the default variable name logsout. When a model is not configured to return a single simulation output, signal logging data is returned to the workspace in a Dataset object with the default variable name logsout.

To access specific elements in a Dataset object, use curly braces, the find function, or the get function. To return the names of the Dataset object elements, use the getElementNames function.

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 resample every element of a structure of timeseries objects obtained by logging a bus.

Access Dataset Object and Elements Programmatically

Open the model sldemo_fuelsys, which models a fault-tolerant fuel control system. For more information about the model, see Model Fault-Tolerant Fuel Control System.

mdl = "sldemo_fuelsys";
open_system(mdl)

In the Configuration Parameters dialog box, in the Data Import/Export pane, note that:

  • The model is not configured to return simulation outputs as a single Simulink.SimulationOutput object.

  • The model uses the variable name sldemo_fuelsys_output for signal logging data.

Simulate the model.

sim(mdl);

Access the Dataset object sldemo_fuelsys_output, which contains the signal logging data.

sldemo_fuelsys_output
sldemo_fuelsys_output = 
Simulink.SimulationData.Dataset 'sldemo_fuelsys_output' with 10 elements

                         Name            BlockPath                                
                         ______________  ________________________________________ 
    1  [1x1 Signal]      ''              sldemo_fuelsys/EGO Fault Switch         
    2  [1x1 Signal]      air_fuel_ratio  sldemo_fuelsys/Engine Gas Dynamics      
    3  [1x1 Signal]      ''              sldemo_fuelsys/Engine Speed Fault Switch
    4  [1x1 Signal]      speed           sldemo_fuelsys/Engine_Speed_Selector    
    5  [1x1 Signal]      ''              sldemo_fuelsys/MAP Fault Switch         
    6  [1x1 Signal]      map             sldemo_fuelsys/MAP_Selector             
    7  [1x1 Signal]      ego             sldemo_fuelsys/O2_Voltage_Selector      
    8  [1x1 Signal]      ''              ...o_fuelsys/Throttle Angle Fault Switch
    9  [1x1 Signal]      throttle        sldemo_fuelsys/Throttle_Angle_Selector  
   10  [1x1 Signal]      fuel            sldemo_fuelsys/To Plant                 

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

To access Dataset object elements, you can use indexing with curly braces. For example, access the throttle element of the signal logging Dataset object using the index 9.

el9 = sldemo_fuelsys_output{9}
el9 = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'throttle'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1x1 timeseries]

The signal data is stored in the Values property of the Simulink.SimulationData.Signal object as a timeseries object. The time values are in the Time property of the timeseries object. The signal values are in the Data property.

el9.Values
  timeseries

  Common Properties:
            Name: 'throttle'
            Time: [203009x1 double]
        TimeInfo: tsdata.timemetadata
            Data: [203009x1 double]
        DataInfo: tsdata.datametadata
el9.Values.Data
ans = 203009×1

   10.0000
   10.0028
   10.0169
   10.0500
   10.1000
   10.1500
   10.2000
   10.2155
   10.2155
   10.2155
      ⋮

Access Signal Logging Data in Simulink.SimulationOutput Object

Open the vdp model which models the second-order Van der Pol differential equation. For more information about the model, see Van der Pol Oscillator.

mdl = "vdp";
open_system(mdl)

Mark the signals coming from the x1, x2, and Mu blocks for logging. Then, simulate the model.

Simulink.sdi.markSignalForStreaming("vdp/x1",1,"on")
Simulink.sdi.markSignalForStreaming("vdp/x2",1,"on")
Simulink.sdi.markSignalForStreaming("vdp/Mu",1,"on")
out = sim("vdp")
out = 
  Simulink.SimulationOutput:
                logsout: [1x1 Simulink.SimulationData.Dataset] 
                   tout: [64x1 double] 
                   yout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

All logged data is returned in a single Simulink.SimulationOutput object with the workspace variable name out. Signal logging data is contained in the SimulationOutput object as a Dataset object with the default name logsout. You can access the logged signal data using dot notation, or you can use the get or find SimulationOutput object functions. Use dot notation to access logsout.

out.logsout
ans = 
Simulink.SimulationData.Dataset 'logsout' with 3 elements

                         Name  BlockPath 
                         ____  _________ 
    1  [1x1 Signal]      ''    vdp/Mu   
    2  [1x1 Signal]      x1    vdp/x1   
    3  [1x1 Signal]      x2    vdp/x2   

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

To access elements of the logsout Dataset object, you can use curly braces, or you can use the get or find Dataset object functions. Use curly braces to access the second element in logsout.

x1sig = out.logsout{2}
x1sig = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'x1'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1x1 timeseries]

The signal data is stored in the Values property of the Simulink.SimulationData.Signal object as a timeseries object. The time values are in the Time property of the timeseries object. The signal values are in the Data property.

x1sig.Values
  timeseries

  Common Properties:
            Name: 'x1'
            Time: [64x1 double]
        TimeInfo: tsdata.timemetadata
            Data: [64x1 double]
        DataInfo: tsdata.datametadata

See Also

Model Settings

Functions

Objects

Related Topics