Contents

db_0114: Simulink patterns for If-then-else-if constructs

ID: Title

db_0114: Simulink® patterns for If-then-else-if constructs

Priority

Strongly recommended

Scope

MAAB

MATLAB Versions

All

Prerequisites

None

Description

Use the following patterns for If-then-else-if constructs within a Simulink model:

Equivalent FunctionalitySimulink Pattern

if then else if with blocks

if (If_Condition) { 
output_signal = If_Value;  
}
else if (Else_If_Condition) { 
output_signal = 
Else_If_Value;
}
else { 
output_signal = 
Else_Value;
} 

Equivalent FunctionalitySimulink Pattern

if then else if with if/then/else subsystems

if(Fault_1_Active &
Fault_2_Active) 
{    
  ErrMsg = SaftyCrit; 
}
else if (Fault_1_Active |
Fault_2_Active)
{    
  ErrMsg = DriveWarn; 
}
else 
{    
  ErrMsg = NoFaults; 
}

Rationale

  • Readability

Last Changed

V2.0

Model Advisor Check

Not applicable

Was this topic helpful?