Main Content

Modeling Guidelines forStateflowCharts

Use these guidelines to efficiently model charts with events, states, and transitions.

Use signals of the same data type for input events

当您使用多个输入事件触发图表时,请验证所有输入信号是否使用相同的数据类型。否则,仿真停止并出现错误消息。有关更多信息,请参阅Data Types Allowed for Input Events.

Use a default transition to mark the first state to become active among exclusive (OR) states

This guideline prevents state inconsistency errors during chart execution.

Use condition actions instead of transition actions whenever possible

Condition actions execute as soon as the condition evaluates to true. Transition actions do not execute until after the transition path is complete, to a terminating junction or a state.

Unless an execution delay is necessary, use condition actions instead of transition actions.

使用明确订购来控制一组传出过渡的测试顺序

You can specifyexplicitorimplicitordering of transitions. By default, a chart uses explicit ordering. If you switch to implicit ordering, the transition testing order can change when graphical objects move.

Verify intended backtracking behavior in flow charts

If your chart contains unintended backtracking behavior, a warning message appears with instructions on how to avoid that problem. For more information, seeBest Practices for Creating Flow Charts.

Use a superstate to enclose substates that share the same state actions

When you have multiple exclusive (OR) states that perform the same state actions, group these states in a superstate and define state actions at that level.

This guideline enables reuse of state actions that apply to multiple substates. You write the state actions only once, instead of writing them separately in each substate.

Note

You cannot use boxes for this purpose because boxes do not support state actions.

UseMATLABfunctions for performing numerical computations in a chart

MATLAB®functions are better at handling numerical computations than graphical functions, truth tables, or Simulink®functions.

Use descriptive names in function signatures

Descriptive function names enhance readability of chart objects.

Use history junctions to record state history

If reentry to a state with exclusive (OR) decomposition depends on the previously active substate, use a history junction. This type of junction records the active substate when the chart exits the state. If you do not record the previously active substate, the default transition occurs and the wrong substate can become active upon state reentry.

请勿使用平行(和)分解状态的历史连接

This guideline prevents compile-time errors. Since all parallel states at a level of hierarchy are active at the same time, history junctions have no meaning.

Use explicit ordering to control the execution order of parallel (AND) states

You can specifyexplicitorimplicitordering of parallel states. By default, a chart uses explicit ordering. If you switch to implicit ordering, the execution order can change when parallel states move.