Documentation Center

  • Trial Software
  • Product Updates

Contents

na_0012: Use of Switch vs. If-Then-Else Action Subsystem

ID: Title

na_0012: Use of Switch vs. If-Then-Else Action Subsystem

Priority

Strongly recommended

Scope

MAAB

MATLAB Versions

All

Prerequisites

None

Description

The Switch block should be used for modeling simple if-then-else structures, if the associated then and else actions involve only the assignment of constant values.

The if-then-else action subsystem construct:

  • Should be used for modeling if-then-else structures, if the associated then and/or else actions require complicated computations. This maximizes simulation efficiency and the efficiency of generated code. (Note that even a basic block, for example a table lookup, may require fairly complicated computations.)

  • Must be used for modeling if-then-else structures, if the purpose of the construct is to avoid an undesirable numerical computation, such as division by zero.

  • Should be used for modeling if-then-else structures, if the explicit or implied then or the else action is just to hold the associated output values.

In other cases, the degree of complexity of the then and/or else action computations and the intelligence of the Simulink® simulation and code generation engines determine the appropriate construct.

These statements also apply to more complicated nested and cascaded if-then-else structures and case structure implementations.

Rationale

  • Readability

  • Verification and Validation

  • Workflow

Last Changed

V2.0

Model Advisor Check

Not applicable

Was this topic helpful?