Main Content

Check relational operators usage

Check ID: mathworks.jmaab_v6.mp_0023

Guideline: mp_0023: Method of using relational operators

Description

Checks the location of variables and constants with respect to relational operators in an expression.

A constant holds a fixed value that does not change over multiple program executions, while a variable holds a value that might change during program execution.

function assign(in)
a = 4;
b = a;
in++;
end

In the above example, a is considered a constant, while in and b are variables.

This check applies to the following target components:

  • MATLAB Function blocks in Simulink®.

  • MATLAB® functions in Stateflow® charts.

  • States, transitions, and truth tables in Stateflow MATLAB charts.

  • External MATLAB files referenced in a model.

This check requires a Simulink Check™ license.

Check Parameterization

This check contains sub-checks that correspond to sub IDs specified in the JMAAB modeling guidelines. You can use the Model Advisor Configuration Editor to specify which sub IDs (one or multiple) to execute.

For reference, the guideline sub ID(s) that are recommended for use by the JMAAB modeling standards organizations are:

  • JMAAB — a1/a2

Select Check external .m files referenced in the model, to include files with a .m extension in the analysis. The check box is selected by default.

Results and Recommended Actions

Guideline Sub IDConditionRecommended Action
mp_0023_a1: Check if variables are placed on the left side of relational operatorsOne or more relational operators have variables on the right side, and constants on the left side of a relational operator.Rewrite relational expressions with variables and constants so that variables are on the left side, and constants are on the right side of a relational operator.
mp_0023_a2: Check if variables are placed on the right side of relational operatorsOne or more relational operators have variables on the left side, and constants on the right side of a relational operator.Rewrite relational expressions with variables and constants so that variables are on the right side, and constants are on the left side of a relational operator.

Capabilities and Limitations

  • Analyzes content of library-linked blocks. By default, the input parameter Follow links is set to on.

  • Analyzes content in masked subsystems. By default, the input parameter Look under masks is set to all.

  • Runs on library models.

  • Allows exclusion of blocks and charts.