Contents

na_0003: Simple logical expressions in If Condition block

ID: Title

na_0003: Simple logical expressions in If Condition block

Priority

Mandatory

Scope

MAAB

MATLAB Versions

All

Prerequisites

None

Description

A logical expression may be implemented within an If Condition block instead of building it up with logical operation blocks, if the expression contains two or fewer primary expressions. A primary expression is defined as one of the following:

  • An input

  • A constant

  • A constant parameter

  • A parenthesized expression containing no operators except zero or one instance of the following operators: < , <= , >, >=, ~=, ==, ~. (See the following examples.)

Exception

A logical expression may contain more than two primary expressions if both of the following are true:

  • The primary expressions are all inputs

  • Only one type of logical operator is present

Examples of Acceptable Exceptions

  • u1 || u2 || u3 ||u4 || u5

  • u1 && u2 && u3 && u4

Examples of Primary Expressions

  • u1

  • 5

  • K

  • (u1 > 0)

  • (u1 <= G)

  • (u1 > U2)

  • (~u1)

  • (EngineState.ENGINE_RUNNING)

Examples of Acceptable Logical Expressions

  • u1 || u2

  • (u1 > 0) && (u1 < 20)

  • (u1 > 0) && (u2 < u3)

  • (u1 > 0) && (~u2)

  • (EngineState.ENGINE_RUNNING > 0) && (PRNDLState.PRNDL_PARK)

      Note:   In this example, EngineState.ENGINE_RUNNING and PRNDLState.PRNDL_PARK are enumeration literals.

Examples of Unacceptable Logical Expressions

u1 && u2 || u3(too many primary expressions)
u1 && (u2 || u3) (unacceptable operator within primary expression)
(u1 > 0) && (u1 < 20) && (u2 > 5) (too many primary expressions that are not inputs)
(u1 > 0) && ((2*u2) > 6)(unacceptable operator within primary expression)

Rationale

  • Readability

  • Workflow

  • Code Generation

Last Changed

V2.2

Model Advisor Check

Not applicable

Was this topic helpful?