Main Content

Stateflow.SimulationData.State

Logged state activity

Description

Use Stateflow.SimulationData.State objects to view the logged activity of a state.

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.

  3. Simulate the model. The signal logging object generated in the MATLAB® workspace contains the Stateflow.SimulationData.State object. Specify the name of the signal logging object using the Signal logging (Simulink) model configuration parameter.

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_car model.

    openExample("sf_car")
    open_system("sf_car/shift_logic", "force")
  2. Open the Symbols pane. In the Simulation tab, in Prepare, click Symbols Pane.

  3. Open the Property Inspector. Configure the downshifting state for logging.

    • Select the downshifting state.

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

    • By default, the logging name for this state is selection_state.downshifting. To assign a shorter name to the state, set Logging Name to Custom and enter DownShifting.

  4. Simulate the model.

  5. To access the state logging object, at the MATLAB command prompt, enter:

    sigsOut
    sigsOut = 
    
    Simulink.SimulationData.Dataset 'sigsOut' with 1 element
    
                            Name         BlockPath                        
                            ___________  ________________________________ 
        1  [1x1 State]      DownShifting  sf_car/shift_logic

  6. To access the logged state data, use the get (Simulink) method.

    downShiftingLog = sigsOut.get("DownShifting")
    downShiftingLog = 
    
      Stateflow.SimulationData.State
      Package: Stateflow.SimulationData
    
      Properties:
             Name: 'DownShifting'
        BlockPath: [1×1 Simulink.SimulationData.BlockPath]
           Values: [1×1 timeseries]
    

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

    T = table(downShiftingLog.Values.Time,downShiftingLog.Values.Data);
    T.Properties.VariableNames = ["Time" "Data"]
    T =
    
      6×2 table
    
           Time       Data
        __________    ____
    
                 0     0  
             14.96     1  
             15.04     0  
             97.56     1  
             97.64     0   
    

Version History

Introduced in R2017b