Main Content

Stateflow.SimulationData.State

State activity during simulation

Description

Use Stateflow.SimulationData.State to log the activity of a state during simulation.

Creation

  1. In the Stateflow® Editor, select a state.

  2. In the Simulation tab, in Prepare, select Log Self Activity. Alternatively, in the Property Inspector,under Logging, select the Log self activity check box.

Properties

expand all

Logging name of the state, specified as a character array. By default, the logging name for a state is the hierarchical name using a period (.) to separate each level in the hierarchy of states. To assign a shorter name to the state, in the Property Inspector, set Logging Name to 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

State activity, specified as a timeseries object. Data values represent whether the state is active (1) or not active (0). Time values correspond to simulation time.

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. Configure the Dining_area state for logging.

    • In the Stateflow Editor, select the Dining_area state.

    • In the Simulation tab, under Prepare, select Log Self Activity.

      In the Property Inspector, under Logging, select the Log self activity check box.

    • By default, the logging name for this state is the hierarchical signal name Check_in.Checked_in.Executive_suite.Dining_area. To assign a shorter name to the state, set Logging Name to Custom and enter Dining Room.

  5. Return to the Simulink® model.

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

  7. Stop the simulation.

  8. 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 State]      Dining Room  sf_semantics_hotel_checkin/Hotel

  9. To access logged elements, use the get (Simulink) method.

    diningLog = logsout.get("Dining Room")
    diningLog = 
    
      Stateflow.SimulationData.State
      Package: Stateflow.SimulationData
    
      Properties:
             Name: 'Dining Room'
        BlockPath: [1×1 Simulink.SimulationData.BlockPath]
           Values: [1×1 timeseries]
    

  10. 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(diningLog.Values.Time,diningLog.Values.Data);
    T.Properties.VariableNames = ["Time" "Data"]
    T =
    
      6×2 table
    
           Time       Data
        __________    ____
    
                 0     0  
        1.8607e+06     1  
        1.9653e+06     0  
        1.9653e+06     1  
        1.9653e+06     0  
        2.2912e+06     1  
    

Version History

Introduced in R2017b