Check logical expressions in If blocks
Check ID:
mathworks.maab.na_0003
Guideline: na_0003: Usage of If blocks
Description
Check If blocks for inappropriate construct of primary expressions in a logical expression.
Identifies instances in an If block where primary expressions are complex.
Primary expressions are defined as:
An input
A constant
A constant parameter
A parenthesized expression containing no operators other than zero or
<
,>
,>=
,<=
,==
,~=
,|
,&
, and~
Examples of primary expressions include:
u1
5
K
(
u1
>0
)(
u1
<=G
)(
u1
>U2
)(~
u1
)
Examples of acceptable logical expressions exceptions include:
u1 | u2
(
(u1 > 0) & (u1 < 20)
(u1 > 0) & (u2 < u3)
(u1 > 0) & (~u2)
This table provides examples of unacceptable logical expressions.
Primary Expression | Reasoning |
---|---|
| Too many primary expressions. |
| Unacceptable operator within primary expression. |
| Too many primary expressions that are not inputs. |
| Unacceptable operator within primary expression. |
Exception
A logical expression can contain more than two primary expressions when both these conditions are met:
The primary expressions are all inputs.
Only one type of logical operator is present.
Examples of acceptable exceptions include:
u1 | u2 | u3 | u4 | u5
u1 & u2 & u3 & u4
Simple "If" Expressions
In the literal interpretation of guideline na_0003, expression
u1 < u2
is a violation. However, the expression follows the
commonly used "If" expression template (<Primary Expression><Operator><Primary
Expression>). So, when logical operators are not used and only one relational operator
is present, the expression satisfies guideline na_0003 and
u1
< u2
is NOT a violation.
This check requires a Simulink® Check™ license.
Check Parameterization
This check does not include sub-checks because the MAB modeling guideline only provides one sub ID.
For reference, the MAB guideline sub ID(s) that are recommended for use by the NA-MAAB and JMAAB modeling standards organizations are:
NA-MAAB — No recommendations
JMAAB — a
Results and Recommended Actions
Condition | Recommended Action |
---|---|
Logical expression contains more than two primary expressions that consist of a constant, constant parameter, and input. | Consider one of the following:
|
Logical expression contains more than two parenthesized expressions that use multiple relational operators | Consider one of the following:
|
Parenthesized expression includes a relational operator other than
zero or < , > ,
>= , <= ,
== , ~= , | ,
& , or ~ . | Consider one of the following:
|
Capabilities and Limitations
Does not flag logical expressions that use only one of these relative operators
<
,>
,>=
,<=
,==
,~=
,|
,&
, and~
Runs on library models.
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
graphical
.