Main Content

mp_0023: Format of relational operations using constants

Since R2024b

Guideline Publication

Control Algorithm Modeling Guidelines - Using MATLAB®, Simulink®, and Stateflow®

Sub ID Recommendations

  • NA-MAAB — a1, a2

  • JMAAB — a1, a2

MATLAB Versions

All

Rule

Sub ID a1

When you are using relational operators with variables and constants, the constants shall be placed on the right-hand side.

Example — Correct
foo = 10;
if bar >= foo
   ret1 = 1;
end
Example — Incorrect
foo = 10;
if foo <= bar
   ret1 = 1;
end

Sub ID a2

When you are using relational operators with variables and constants, the constants shall be placed on the left-hand side.

Example — Correct
foo = 10;
if foo <= bar
   ret1 = 1;
end
Example — Incorrect
foo = 10;
if bar >= foo
   ret1 = 1;
end

Rationale

Sub IDs a1, a2:

  • Readability is improved by standardizing the way to write statements.

Verification

Model Advisor check: Check relational operators usage (Simulink Check)

Last Changed

R2024b

Version History

Introduced in R2024b