Main Content


Data values during simulation


Use Stateflow.SimulationData.Data to log the values of local and output data during simulation.


  1. In the Symbols pane, select a local or output data object.

  2. In the Property Inspector, under Logging, select the Log signal data check box.


expand all

Logging name of the data object, specified as a character array. By default, the logging name for a data object is the name of the data object. To assign another name to the data object, in the Property Inspector, under Logging Name, select Custom and enter a custom logging name.

Data Types: char

Block path for the source block, specified as a Simulink.SimulationData.BlockPath (Simulink) object.

Data Types: Simulink.SimulationData.BlockPath

Logged data and time, specified as a timeseries object.

Data Types: timeseries

Object Functions

plot (Simulink)Plot simulation output data in the Simulation Data Inspector


collapse all

  1. Open the sf_semantics_hotel_checkin model.

  2. Open the Hotel chart.

  3. Open the Symbols pane. In the Simulation tab, in Prepare, click Symbols Pane.

  4. Open the Property Inspector. In the Simulation tab, in Prepare, click Property Inspector.

  5. Configure the service local data for logging.

    • In the Symbols pane, select service.

    • In the Property Inspector, on the Logging tab, select the Log signal data check box.

  6. Return to the Simulink® model.

  7. Simulate the model. After starting the simulation, check into the hotel by toggling the first switch and order room service multiple times by toggling the second switch. During simulation, Stateflow® saves logged data in a Simulink.SimulationData.Dataset (Simulink) signal logging object. The default name of the signal logging object is logsout. For more information, see Export Signal Data Using Signal Logging (Simulink).

  8. Stop the simulation.

  9. To access the signal logging object, at the MATLAB® command prompt, enter:

    logsout = 
    Simulink.SimulationData.Dataset 'logsout' with 1 element
                            Name         BlockPath                        
                            ___________  ________________________________ 
        1  [1x1 Data ]      service      sf_semantics_hotel_checkin/Hotel

  10. To access logged element, use the get (Simulink) method.

    serviceLog = logsout.get("service")
    serviceLog = 
      Package: Stateflow.SimulationData
             Name: 'service'
        BlockPath: [1×1 Simulink.SimulationData.BlockPath]
           Values: [1×1 timeseries]

  11. To access the logged data and time of each logged element, use the Values.Data and Values.Time properties. For example, arrange logged data in tabular form by using the table function.

    T = table(serviceLog.Values.Time,serviceLog.Values.Data);
    T.Properties.VariableNames = ["Time" "Data"]
    T =
      6×2 table
           Time       Data
        __________    ____
        1.7076e+06     0  
        1.8607e+06     1  
        1.9653e+06     2  
        1.9653e+06     3  
        1.9653e+06     4  
        2.2912e+06     5  

Version History

Introduced in R2017b