na_0001: Standard usage of Stateflow operators
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB®, Simulink®, and Stateflow®
Sub ID Recommendations
- NA-MAAB — No recommendations 
- JMAAB — a, b1/b2/b3, c 
MATLAB Versions
All
Rule
Sub ID a
When Stateflow
    Chart (Stateflow) property Action Language is set to
     C, operators (&, |,
     ^, ~) shall be used only for bit operations.
Not Applicable
Operators (&, |, ^,
      ~) are used for bit operations.

Operators (&, |, ^,
      ~) are not used for bit operations.

Sub ID b1
When Stateflow
    Chart (Stateflow) property Action Language is set to
     C, operator ~= shall be used for inequality
    operations.
Not Applicable

Sub ID b2
When Stateflow
    Chart (Stateflow) property Action Language is set to
     C, operator != shall be used for inequality
    operations.
Not Applicable

Sub ID b3
When Stateflow
    Chart (Stateflow) property Action Language is set to
     C, operator <> shall be used for inequality
    operations.
Not Applicable

Sub ID c
When Stateflow
    Chart (Stateflow) property Action Language is set to
     C, operation ! shall be used for logical negation.
Not Applicable

An operator other than ! should be used for logical negation.

Rationale
Sub ID a:
- When either of these Stateflow Chart properties are set as follows: - Action Language is set to - MATLAB
- Action Language is set to - Cand Enable C-bit operations (Stateflow) is selected
 - &&and- &,- ||,and- |, have the same calculation function. However, when- &&and- &or- ||and- |are combined in the same chart, it can be difficult to determine whether these are separate calculation functions or the same calculation function.
Sub IDs b1, b2, b3:
- Consistent use of equality operators improves readability. 
Sub ID c:
- Consistent use of logical negation operators improves readability. 
- When C-bit operations are enabled is selected, the function of the - !operator remains the same and is not affected by logic changes that result from changing the setting.
Verification
Model Advisor check: Check Stateflow operators (Simulink Check)
Last Changed
R2020a
See Also
- Modify the Action Language for a Chart (Stateflow) 
- Differences Between MATLAB and C as Action Language Syntax (Stateflow) 
Version History
Introduced in R2020a