Main Content

na_0001: Standard usage of Stateflow operators

Since R2020a

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.

Custom Parameter

Not Applicable

Example — Correct

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

Example — Incorrect

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.

Custom Parameter

Not Applicable

Example — Correct

Sub ID b2

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

Custom Parameter

Not Applicable

Example — Correct

Sub ID b3

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

Custom Parameter

Not Applicable

Example — Correct

Sub ID c

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

Custom Parameter

Not Applicable

Example — Correct

Example — Incorrect

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:

    && 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

Version History

Introduced in R2020a