Main Content

setActive

Set state as active

    Description

    setActive(stateOp) sets the state that corresponds to the operating point stateOp as active. stateOp must be an operating point for a leaf state. When you call setActive, the chart maintains state consistency by:

    • Exiting and entering the appropriate states

    • Resetting temporal counters for newly active states

    • Updating values of active state data

    • Enabling or disabling function-call subsystems and Simulink® functions that bind to states

    However, the chart does not perform exit actions for the previously active states or entry actions for the newly active state. Additionally, the state does not reinitialize any state-parented local data.

    example

    Examples

    collapse all

    1. Open the sf_car model.

      openExample("sf_car")

      For more information about this model, see Simulate Chart as a Simulink Block with Local Events.

    2. Set the model to save the final operating point. Open the Configuration Parameters dialog box and, in the Data Import/Export pane:

      1. Select Final states and enter a name for the operating point. For this example, use xSteadyState.

      2. Select Save final operating point.

      3. Click OK.

    3. Set the stop time for this simulation segment. In the Simulation tab, set Stop Time to 3.

    4. Run the simulation.

    5. Access the Stateflow.op.BlockOperatingPoint object that contains the operating point information for the shift_logic chart.

      blockpath = "sf_car/shift_logic";
      op = get(xSteadyState,blockpath)
      op = 
      
      Block: "shift_logic"    (handle)    (active)
        Path:     sf_car/shift_logic
      
        Contains:
      
          + gear_state                     "State (AND)"                        (active)       
          + selection_state                "State (AND)"                        (active)       
            gear                           "State output data"                  gearType [1, 1]
            down_th                        "Local data"                         double [1, 1]  
            up_th                          "Local data"                         double [1, 1]  
            datasetWrittenToVector         "Data set written to vector"         logical 4x1  
    6. Access the Stateflow.op.OperatingPointContainer object that contains the operating point information for the gear_state state.

      op.gear_state
      ans = 
      
      State: "gear_state"    (handle)    (active)
        Path:     sf_car/shift_logic/gear_state
      
        Contains:
      
          + first          "State (OR)"         (active)
          + fourth         "State (OR)"                 
          + second         "State (OR)"                 
          + third          "State (OR)"
    7. Highlight the states that are active in the chart at t = 3.

      highlightActiveStates(op)

      Stateflow chart showing active states.

    8. Change the substate activity in the state gear_state state to reflect a change in gear.

      setActive(op.gear_state.second)

      Stateflow chart showing active states.

    9. Verify that the substate second in the state gear_state is active in the modified operating point.

      isActive(op.gear_state.second)
      ans =
      
        logical
      
         1

    10. Remove the highlighting of active states in the Stateflow® Editor.

      removeHighlighting(op)

    Input Arguments

    collapse all

    Operating point for a leaf state, specified as a Stateflow.op.OperatingPointContainer object.

    Version History

    Introduced in R2009b