Main Content

Stateflow.SimulationData.Data

Data values during simulation

Description

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

Creation

  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.

Properties

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 data in Simulation Data Inspector

Examples

collapse all

  1. Open the sf_semantics_hotel_checkin model.

    openExample("sf_semantics_hotel_checkin")

    For more information about this example, see How Stateflow Objects Interact During Execution.

  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 twice and order room service by toggling the second switch multiple times. 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 Save Signal Data Using Signal Logging (Simulink).

  8. Stop the simulation.

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

    logsout
    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 = 
    
      Stateflow.SimulationData.Data
      Package: Stateflow.SimulationData
    
      Properties:
             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
        __________    ____
    
                 0     0
        1.7076e+06     0  
        1.8607e+06     1  
        1.9653e+06     2  
        1.9653e+06     3  
        1.9653e+06     4  
        2.2912e+06     5  
    
    In this example, the data points with values of 0 correspond to when the chart initializes the local data service to 0 at time 0 and when a default transition sets service to 0 at time 1.7076e+06.

Tips

  • Stateflow.SimulationData.Data objects record a data point every time that the Stateflow chart writes to the data you are logging, even if the data does not change value. For example, in Access Logged Data, the data points with values of 0 correspond to when the chart initializes the local data service to 0 at time 0 and when a default transition sets service to 0 at time 1.7076e+06.

Version History

Introduced in R2017b