MATLAB: How to determine the “active state” in a Stateflow diagram for Stateflow 7.0 (R2007b)

activehasoutputdatastatestateflow

I would like to be able to get the currently active state of a state machine implemented using Stateflow. During simulation of the Stateflow chart, the active state is highlighted, however, I would like to be able to determine the currently active state via the command line interface.

Best Answer

The ability to determine the currently active state of a Stateflow chart during simulation is not available in Stateflow.
To work around this issue,
1. Right-click on the Stateflow chart in the Simulink block diagram
2. Select the "Log Chart Signals" option.
3. Select all the states that you would like to log, together with all parameters and local variables.
4. Once the simulation completes, a Simulink.ModelDataLog object with the name "logsout" is created in the MATLAB workspace.
5. To access the activity data of each state, enter the following command at the MATLAB command prompt:
logsout.Chart.<name-of-state>.Data
To list all available states and parameters, type:
logsout.Chart
Also refer to the related solution for additional information.
Related Question