simulink_mab_guidelines
simulink_mab_guidelines
R2024b
How to Contact MathWorks
Phone: 508-647-7000
Introduction
1
Purpose of the Guidelines and Template . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Naming Conventions
2
General Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Simulink
3
Configuration Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-68
Stateflow
4
Stateflow Blocks / Data / Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
v
Stateflow Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29
Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-176
MATLAB
5
MATLAB Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Considerations
6
Considerations for Determining Guideline Operation Rules . . . . . . . . . . . 6-2
Process Definition and Development Environment . . . . . . . . . . . . . . . . . . 6-2
MATLAB and Simulink Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
MATLAB and Simulink Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Usable Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Using Optimization and Configuration Parameters . . . . . . . . . . . . . . . . . . 6-3
vi Contents
Stateflow Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-24
Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-31
Modeling Knowledge
B
Usage Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2
Simulink Patterns for If, elseif, else Constructs . . . . . . . . . . . . . . . . . . . . . B-2
Simulink Patterns for case Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2
Simulink Patterns for Logical Constructs . . . . . . . . . . . . . . . . . . . . . . . . . B-3
Simulink Patterns for Vector Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-4
Using Switch and If, Elseif, Else Action Subsystems . . . . . . . . . . . . . . . . . B-6
Use of If, Elseif, Else Action Subsystem to Replace Multiple Switches . . . . B-8
Usage Rules for Action Subsystems Using Conditional Control Flow . . . . B-12
Test for Information From Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-16
Flow Chart Patterns for Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-17
Flow Chart Patterns for Condition Actions . . . . . . . . . . . . . . . . . . . . . . . B-18
Flow Chart Patterns for If, Elseif, Else Constructs . . . . . . . . . . . . . . . . . B-19
Flow Chart Patterns for Case Constructs . . . . . . . . . . . . . . . . . . . . . . . . B-20
Flow Chart Patterns for Loop Constructs . . . . . . . . . . . . . . . . . . . . . . . . B-21
State Machine Patterns for Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . B-22
State Machine Patterns for Transition Actions . . . . . . . . . . . . . . . . . . . . B-22
jc_0321Limiting State Layering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-23
Number of States per Stateflow Container . . . . . . . . . . . . . . . . . . . . . . . B-24
Function Call from Stateflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-24
Function Types Available in Stateflow . . . . . . . . . . . . . . . . . . . . . . . . . . B-24
Glossary
C
vii
1
Introduction
• Readability
Note Model runtime errors and recommendations that cannot be implemented are outside of the
scope of these rules.
Guidelines are documented by using a standard template. Use of this template is recommended when
creating original guidelines.
Note This template specifies the minimum requirements that are needed to understand a guideline.
New items can be added to the template as long as they do not duplicate existing information.
1-2
Purpose of the Guidelines and Template
1-3
1 Introduction
• xy_0000a ― Represents a
selectable (user’s choice)
option
• xy_0000b1
xy_0000b2
1-4
Purpose of the Guidelines and Template
1-5
1 Introduction
• By Product > Simulink Check > Modeling Standards > MAB Checks
• By Task > Modeling Standards for MAB
• No check — Indicates that the guideline can be checked by using a Model Advisor check, however,
the check does not currently exist.
• Not checkable — Indicates that it is not possible to verify compliance to this guideline by using a
Model Advisor check.
(Version 6.0)
ar_0001: Usable characters for “Check file names” (Simulink mathworks.jmaab.ar_0001
file names Check)
ar_0002: Usable characters for “Check folder names” (Simulink mathworks.jmaab_v6.ar_00
folder names Check) 02
db_0032: Signal line “Check signal line connections” mathworks.jmaab_v6.db_00
connections (Simulink Check) 32
db_0042: Usage of Inport and “Check position of Inport and mathworks.jmaab.db_0042
Outport blocks Outport blocks” (Simulink
Check)
db_0043: Model font and font “Check model font settings” mathworks.jmaab.db_0043
size (Simulink Check)
db_0081: Unconnected signals “Check for unconnected signal mathworks.jmaab.db_0081
and blocks lines and blocks” (Simulink
Check)
db_0097: Position of labels for “Check position of signal labels” mathworks.jmaab_v6.db_00
signals and buses (Simulink Check) 97
db_0110: Block parameters “Check usage of tunable mathworks.maab.db_0110
parameters in blocks” (Simulink
Check)
db_0112: Usage of index “Check Indexing Mode” mathworks.jmaab.db_0112
(Simulink Check)
1-6
Model Advisor Checks for MAB Modeling Guidelines
(Version 6.0)
db_0123: Stateflow port names “Check for names of Stateflow mathworks.maab.db_0123
ports and associated signals”
(Simulink Check)
db_0125: Stateflow local data “Check definition of Stateflow mathworks.jmaab_v6.db_01
data” (Simulink Check) 25
db_0126: Defining Stateflow “Check definition of Stateflow mathworks.jmaab.db_0126
events events” (Simulink Check)
db_0127: Limitation on MATLAB “Check for MATLAB expressions mathworks.jmaab_v6.db_01
commands in Stateflow blocks in Stateflow charts” (Simulink 27
Check)
db_0129: Stateflow transition “Check for Stateflow transition mathworks.jmaab_v6.db_01
appearance appearance” (Simulink Check) 29
db_0132: Transitions in flow “Check transitions in Stateflow mathworks.jmaab.db_0132
charts Flow charts” (Simulink Check)
db_0137: States in state “Check for state in state mathworks.jmaab.db_0137
machines machines” (Simulink Check)
db_0140: Display of block “Check for display of block mathworks.maab.db_0140
parameters parameter” (Simulink Check)
db_0141: Signal flow in “Check signal flow in model” mathworks.maab.db_0141
Simulink models (Simulink Check)
db_0142: Position of block “Check whether block names mathworks.maab.db_0142
names appear below blocks” (Simulink
Check)
db_0143: Usable block types in “Check for mixing basic blocks mathworks.maab.db_0143
model hierarchy and subsystems” (Simulink
Check)
db_0144: Use of subsystems Not checkable
db_0146: Block layout in “Check position of conditional mathworks.jmaab.db_0146
conditional subsystems blocks and iterator blocks”
(Simulink Check)
hd_0001: Prohibited Simulink “Check for prohibited sink mathworks.maab.hd_0001
sinks blocks” (Simulink Check)
jc_0008: Definition of signal “Check definition of signal mathworks.jmaab.jc_0008
names labels” (Simulink Check)
jc_0009: Signal name “Check signal name mathworks.jmaab_v6.jc_00
propagation propagation” (Simulink Check) 09
jc_0011: Optimization “Check Implement logic signals mathworks.maab.jc_0011
parameters for Boolean data as Boolean data (vs. double)”
types (Simulink Check)
jc_0021: Model diagnostic “Check model diagnostic mathworks.maab.jc_0021
settings parameters” (Simulink Check)
1-7
1 Introduction
(Version 6.0)
jc_0061: Display of block names “Check the display attributes of mathworks.maab.jc_0061
block names” (Simulink Check)
jc_0081: Inport and Outport “Check display for port blocks” mathworks.maab.jc_0081
block icon display (Simulink Check)
jc_0110: Direction of block “Check block orientation” mathworks.jmaab.jc_0110
(Simulink Check)
jc_0121: Usage of add and “Check usage of Sum blocks” mathworks.jmaab.jc_0121
subtraction blocks (Simulink Check)
jc_0131: Usage of Relational “Check usage of Relational mathworks.maab.jc_0131
Operator blocks Operator blocks” (Simulink
Check)
jc_0141: Usage of the Switch “Check usage of Switch blocks” mathworks.maab.jc_0141
blocks (Simulink Check)
jc_0161: Definition of Data Store “Check for usage of Data Store mathworks.jmaab.jc_0161
Memory blocks Memory blocks” (Simulink
Check)
jc_0171: Clarification of “Check connections between mathworks.jmaab.jc_0171
connections between structural structural subsystems”
subsystems (Simulink Check)
jc_0201: Usable characters for “Check subsystem names” mathworks.jmaab.jc_0201
subsystem names (Simulink Check)
jc_0211: Usable characters for “Check port block names” mathworks.jmaab.jc_0211
Inport blocks and Outport block (Simulink Check)
jc_0222: Usable characters for “Check usable characters for mathworks.jmaab.jc_0222
signal and bus names signal names and bus names”
(Simulink Check)
jc_0231: Usable characters for “Check character usage in block mathworks.jmaab.jc_0231
block names names” (Simulink Check)
jc_0232: Usable characters for “Check usable characters for mathworks.jmaab_v6.jc_02
parameter names parameter names” (Simulink 32
Check)
jc_0241: Length restriction for “Check length of model file mathworks.jmaab.jc_0241
model file names name” (Simulink Check)
jc_0242: Length restriction for “Check length of folder name at mathworks.jmaab.jc_0242
folder names every level of model path”
(Simulink Check)
jc_0243: Length restriction for “Check length of subsystem mathworks.jmaab.jc_0243
subsystem names names” (Simulink Check)
jc_0244: Length restriction for “Check length of Inport and mathworks.jmaab.jc_0244
Inport and Outport names Outport names” (Simulink
Check)
1-8
Model Advisor Checks for MAB Modeling Guidelines
(Version 6.0)
jc_0245: Length restriction for “Check length of signal and bus mathworks.jmaab.jc_0245
signal and bus names names” (Simulink Check)
jc_0246: Length restriction for “Check length of parameter mathworks.jmaab.jc_0246
parameter name names” (Simulink Check)
jc_0247: Length restriction for “Check length of block names” mathworks.jmaab.jc_0247
block names (Simulink Check)
jc_0281: Trigger signal names “Check trigger signal names” mathworks.jmaab.jc_0281
(Simulink Check)
jc_0451: Use of unary minus on “Check usage of unary minus mathworks.jmaab.jc_0451
unsigned integers operations in Stateflow charts”
(Simulink Check)
jc_0481: Use of hard equality “Check usage of floating-point mathworks.jmaab_v6.jc_04
comparisons for floating point expressions in Stateflow charts” 81
numbers in Stateflow (Simulink Check)
jc_0491: Reuse of Stateflow data Not checkable
jc_0501: Format of entries in a “Check entry formatting in mathworks.jmaab.jc_0501
State block State blocks in Stateflow charts”
(Simulink Check)
jc_0511: Return values from a “Check return value mathworks.maab.jc_0511
graphical function assignments in Stateflow
graphical functions” (Simulink
Check)
jc_0531: Default transition “Check default transition mathworks.jmaab.jc_0531
placement in Stateflow charts”
(Simulink Check)
jc_0602: Consistency in model “Check for consistency in model mathworks.jmaab.jc_0602
element names element names” (Simulink
Check)
jc_0603: Model description “Check Model Description” mathworks.jmaab.jc_0603
(Simulink Check)
jc_0604: Using block shadow “Check if blocks are shaded in mathworks.jmaab.jc_0604
the model” (Simulink Check)
jc_0610: Operator order for “Check operator order of mathworks.jmaab.jc_0610
multiplication and division block Product blocks” (Simulink
Check)
jc_0611: Input sign for “Check signs of input signals in mathworks.jmaab.jc_0611
multiplication and division product blocks” (Simulink
blocks Check)
jc_0621: Usage of Logical “Check icon shape of Logical mathworks.jmaab.jc_0621
Operator blocks Operator blocks” (Simulink
Check)
1-9
1 Introduction
(Version 6.0)
jc_0622: Usage of Fcn blocks “Check for parentheses in Fcn mathworks.jmaab.jc_0622
block expressions” (Simulink
Check)
jc_0623: Usage of continuous- “Check usage of Memory and mathworks.jmaab.jc_0623
time Delay blocks and discrete- Unit Delay blocks” (Simulink
time Delay blocks Check)
jc_0624: Usage of Tapped Delay “Check for cascaded Unit Delay mathworks.jmaab.jc_0624
blocks/Delay blocks blocks” (Simulink Check)
jc_0626: Usage of Lookup Table “Check usage of Lookup Tables” mathworks.jmaab.jc_0626
blocks (Simulink Check)
jc_0627: Usage of Discrete-Time “Check usage of Discrete-Time mathworks.jmaab_v6.jc_06
Integrator blocks Integrator block” (Simulink 27
Check)
jc_0628: Usage of Saturation “Check usage of the Saturation mathworks.jmaab.jc_0628
blocks blocks” (Simulink Check)
jc_0630: Usage of Multiport “Check settings for data ports in mathworks.jmaab_v6.jc_06
Switch blocks Multiport Switch blocks” 30
(Simulink Check)
jc_0640: Initial value settings “Check undefined initial output mathworks.jmaab.jc_0640
for Outport blocks in conditional for conditional subsystems”
subsystems (Simulink Check)
jc_0641: Sample time setting “Check for sample time setting” mathworks.jmaab.jc_0641
(Simulink Check)
jc_0642: Integer rounding mode “Check Signed Integer Division mathworks.jmaab.jc_0642
setting Rounding mode” (Simulink
Check)
jc_0643: Fixed-point setting “Check usage of fixed-point data mathworks.jmaab.jc_0643
type with non-zero bias”
(Simulink Check)
jc_0644: Type setting “Check type setting by data mathworks.jmaab_v6.jc_06
objects” (Simulink Check) 44
jc_0645: Parameter definition “Check if tunable block mathworks.jmaab.jc_0645
for calibration parameters are defined as
named constants” (Simulink
Check)
jc_0650: Block input/output data “Check input and output mathworks.jmaab.jc_0650
type with switching function datatype for Switch blocks”
(Simulink Check)
jc_0651: Implementing a type “Check Output data type of mathworks.jmaab_v6.jc_06
conversion operation blocks” (Simulink 51
Check)
1-10
Model Advisor Checks for MAB Modeling Guidelines
(Version 6.0)
jc_0653: Delay block layout in “Check for avoiding algebraic mathworks.jmaab.jc_0653
feedback loops loops between subsystems”
(Simulink Check)
jc_0655: Prohibition of logical “Check prohibited comparison mathworks.jmaab.jc_0655
value comparison in Stateflow operation of logical type
signals” (Simulink Check)
jc_0656: Usage of Conditional “Check default/else case in mathworks.jmaab.jc_0656
Control blocks Switch Case blocks and If
blocks” (Simulink Check)
jc_0657: Retention of output Not checkable
value based on conditional
control flow blocks and Merge
blocks
jc_0659: Usage restrictions of “Check usage of Merge block” mathworks.jmaab.jc_0659
signal lines input to Merge (Simulink Check)
blocks
jc_0700: Unused data in “Check for unused data in mathworks.jmaab.jc_0700
Stateflow block Stateflow Charts” (Simulink
Check)
jc_0701: Usable number for first “Check usable number for first mathworks.jmaab.jc_0701
index index” (Simulink Check)
jc_0702: Use of named Stateflow “Check usage of numeric literals mathworks.jmaab.jc_0702
parameters and constants in Stateflow” (Simulink Check)
jc_0711: Division in Stateflow Not checkable
jc_0712: Execution timing for “Check execution timing for mathworks.jmaab.jc_0712
default transition path default transition path”
(Simulink Check)
jc_0721: Usage of parallel states “Check usage of parallel states” mathworks.jmaab.jc_0721
(Simulink Check)
jc_0722: Local data definition in “Check scope of data in parallel mathworks.jmaab.jc_0722
parallel states states” (Simulink Check)
jc_0723: Prohibited direct “Check usage of transitions to mathworks.jmaab.jc_0723
transition from external state to external states” (Simulink
child state Check)
jc_0730: Unique state name in “Check uniqueness of State mathworks.jmaab.jc_0730
Stateflow blocks names” (Simulink Check)
jc_0731: State name format “Check usage of State names” mathworks.jmaab.jc_0731
(Simulink Check)
jc_0732: Distinction between “Check uniqueness of Stateflow mathworks.jmaab.jc_0732
state names, data names, and state, data and event names”
event names (Simulink Check)
1-11
1 Introduction
(Version 6.0)
jc_0733: Order of state action “Check order of state action mathworks.jmaab.jc_0733
types types” (Simulink Check)
jc_0734: Number of state action “Check repetition of action mathworks.jmaab.jc_0734
types types” (Simulink Check)
jc_0736: Uniform indentations “Check indentation of code in mathworks.jmaab.jc_0736
in Stateflow blocks Stateflow states” (Simulink
Check)
jc_0738: Usage of Stateflow “Check usage of Stateflow mathworks.jmaab.jc_0738
comments comments” (Simulink Check)
jc_0740: Limitation on use of “Check if state action type 'exit' mathworks.jmaab.jc_0740
exit state action is used in the model” (Simulink
Check)
jc_0741: Timing to update data “Check updates to variables mathworks.jmaab_v6.jc_07
used in state chart transition used in state transition 41
conditions conditions” (Simulink Check)
jc_0751: Backtracking “Check for unexpected mathworks.jmaab.jc_0751
prevention in state transition backtracking in state
transitions” (Simulink Check)
jc_0752: Condition action in “Check usage of parentheses in mathworks.jmaab.jc_0752
transition label Stateflow transitions” (Simulink
Check)
jc_0753: Condition actions and “Check condition actions and mathworks.jmaab_v6.jc_07
transition actions in Stateflow transition actions in Stateflow” 53
(Simulink Check)
jc_0760: Starting point of “Check starting point of internal mathworks.jmaab.jc_0760
internal transition transition in Stateflow”
(Simulink Check)
jc_0762: Prohibition of state “Check prohibited combination mathworks.jmaab.jc_0762
action and flow chart of state action and flow chart”
combination (Simulink Check)
jc_0763: Usage of multiple “Check usage of internal mathworks.jmaab.jc_0763
internal transitions transitions in Stateflow states”
(Simulink Check)
jc_0770: Position of transition “Check placement of Label mathworks.jmaab_v6.jc_07
label String in Transitions” (Simulink 70
Check)
jc_0771: Comment position in “Check position of comments in mathworks.jmaab.jc_0771
transition labels transition labels” (Simulink
Check)
jc_0772: Execution order and “Check usage of transition mathworks.jmaab.jc_0772
transition conditions of conditions in Stateflow
transition lines transitions” (Simulink Check)
1-12
Model Advisor Checks for MAB Modeling Guidelines
(Version 6.0)
jc_0773: Unconditional “Check usage of unconditional mathworks.jmaab.jc_0773
transition of a flow chart transitions in flow charts”
(Simulink Check)
jc_0774: Comments for through “Check for comments in mathworks.jmaab.jc_0774
transition unconditional transitions”
(Simulink Check)
jc_0775: Terminating junctions “Check terminal junctions in mathworks.jmaab.jc_0775
in flow charts Stateflow” (Simulink Check)
jc_0790: Action language of “Check Stateflow chart action mathworks.jmaab.jc_0790
Chart block language” (Simulink Check)
jc_0791: Duplicate data name “Check duplication of Simulink mathworks.jmaab.jc_0791
definitions data names” (Simulink Check)
jc_0792: Unused Data “Check unused data in Simulink mathworks.jmaab.jc_0792
Model” (Simulink Check)
jc_0794: Division in Simulink “Check for division by zero in mathworks.jmaab.jc_0794
Simulink” (Simulink Check)
jc_0795: Usable characters for “Check usable characters for mathworks.jmaab.jc_0795
Stateflow data names Stateflow data names”
(Simulink Check)
jc_0796: Length restriction for “Check length of Stateflow data mathworks.jmaab.jc_0796
Stateflow data names name” (Simulink Check)
jc_0797: Unconnected “Check for unconnected objects mathworks.jmaab.jc_0797
transitions / states / connective in Stateflow Charts” (Simulink
junctions Check)
jc_0800: Comparing floating- “Check comparison of floating mathworks.jmaab.jc_0800
point types in Simulink point types in Simulink”
(Simulink Check)
jc_0801: Prohibited use of the /* “Check for use of C-style mathworks.jmaab.jc_0801
and */ comment symbols comment symbols” (Simulink
Check)
jc_0802: Prohibited use of “Check for implicit type casting mathworks.jmaab.jc_0802
implicit type casting in in Stateflow” (Simulink Check)
Stateflow
jc_0803: Passing values to Not checkable
library functions
jc_0804: Prohibited use of “Check usage of graphical mathworks.jmaab.jc_0804
recursive calls with graphical functions in Stateflow”
functions (Simulink Check)
jc_0805: Numerical operation No check
block inputs
1-13
1 Introduction
(Version 6.0)
jc_0806: Detecting incorrect “Check diagnostic settings for mathworks.jmaab.jc_0806
calculation results incorrect calculation results”
(Simulink Check)
jc_0900: Usable characters for “Check bus and enumeration mathworks.jmaab_v6.jc_09
data type definition data type names” (Simulink 00
Check)
jc_0901: Length restriction for “Check length of bus and mathworks.jmaab_v6.jc_09
Bus and Enumeration data type enumeration data type names” 01
names (Simulink Check)
jc_0902: Arrowhead size of “Check arrowhead size of mathworks.jmaab_v6.jc_09
transition lines transition lines” (Simulink 02
Check)
jc_0903: Prohibition of “Check for prohibited mathworks.jmaab_v6.jc_09
overlapping or crossing of overlapping or intersecting 03
blocks and signal lines blocks and signal lines”
(Simulink Check)
jc_0904: Prohibition of overlap/ “Check for prohibited mathworks.jmaab_v6.jc_09
intersection of states and overlapping of states and 04
transition lines transition lines in Stateflow
charts” (Simulink Check)
jc_0905: Usable characters for “Check data names in MATLAB mathworks.jmaab_v6.jc_09
data names in Functions functions” (Simulink Check) 05
jc_0906: Length restriction of “Check the length of data names mathworks.jmaab_v6.jc_09
data names in MATLAB in MATLAB functions” (Simulink 06
Functions Check)
jc_0907: Size of a Junction “Check size of junctions” mathworks.jmaab_v6.jc_09
(Simulink Check) 07
jm_0002: Block resizing No check
jm_0011: Pointers in Stateflow “Check for pointers in Stateflow mathworks.maab.jm_0011
charts” (Simulink Check)
jm_0012: Usage restrictions of “Check for usage of events in mathworks.jmaab_v6.jm_00
events and broadcasting events Stateflow charts” (Simulink 12
Check)
mp_0007: How to describe “Check description of execution mathworks.jmaab_v6.mp_00
executable statements statements” (Simulink Check) 07
mp_0008: Format of “Check for spaces between mathworks.jmaab_v6.mp_00
parentheses function or variable names and 08
left parenthesis symbol”
(Simulink Check)
mp_0010: Precedence of “Check for operator mathworks.jmaab_v6.mp_00
Operators in Arithmetic precedence” (Simulink Check) 10
Expressions
1-14
Model Advisor Checks for MAB Modeling Guidelines
(Version 6.0)
mp_0011: Method of inserting a “Check spaces in expressions” mathworks.jmaab_v6.mp_00
single-width space (Simulink Check) 11
mp_0022: Format of Conditional “Check description of mathworks.jmaab_v6.mp_00
Expressions conditional expressions” 22
(Simulink Check)
mp_0023: Format of relational “Check relational operators mathworks.jmaab_v6.mp_00
operations using constants usage” (Simulink Check) 23
mp_0032: Function header “Check function headers” mathworks.jmaab_v6.mp_00
information (Simulink Check) 32
mp_0034: Number of lines in a “Check number of lines of mathworks.jmaab_v6.mp_00
function functions” (Simulink Check) 34
mp_0040: Using the return “Check for utilization of the mathworks.jmaab_v6.mp_00
value of a function return value of functions” 40
(Simulink Check)
mp_0046: Usage of expressions “Check array indices” (Simulink mathworks.jmaab_v6.mp_00
in array indices Check) 46
mp_0047: Conditions that a “Check for usage of nonempty mathworks.jmaab_v6.mp_00
nonempty statement must statements” (Simulink Check) 47
satisfy
na_0001: Standard usage of “Check Stateflow operators” mathworks.jmaab.na_0001
Stateflow operators (Simulink Check)
na_0002: Appropriate usage of “Check fundamental logical and mathworks.jmaab.na_0002
basic logical and numerical numerical operations” (Simulink
operations Check)
na_0003: Usage of If blocks “Check logical expressions in If mathworks.maab.na_0003
blocks” (Simulink Check)
na_0004: Simulink model “Check for Simulink diagrams mathworks.maab.na_0004
appearance settings using nonstandard display
attributes” (Simulink Check)
na_0008: Display of labels on “Check signal line labels” mathworks.maab.na_0008
signals (Simulink Check)
na_0009: Entry versus “Check for propagated signal mathworks.maab.na_0009
propagation of signal labels labels” (Simulink Check)
na_0010: Usage of vector and “Check usage of vector and bus mathworks.jmaab.na_0010
bus signals signals” (Simulink Check)
na_0011: Scope of Goto and “Check scope of From and Goto mathworks.jmaab_v6.na_00
From blocks blocks” (Simulink Check) 11
na_0016: Source lines of “Check lines of code in MATLAB mathworks.jmaab.na_0016
MATLAB Functions Functions” (Simulink Check)
na_0017: Number of called “Check the number of function mathworks.jmaab.na_0017
function levels calls in MATLAB Function
blocks” (Simulink Check)
1-15
1 Introduction
(Version 6.0)
na_0018: Number of nested if/ “Check nested conditions in mathworks.jmaab.na_0018
else and case statement MATLAB Functions” (Simulink
Check)
na_0019: Restricted variable “Check usage of restricted mathworks.maab.na_0019
names variable names” (Simulink
Check)
na_0020: Number of inputs to “Check for missing ports in mathworks.jmaab_v6.na_00
variant subsystems Variant Subsystems” (Simulink 20
Check)
na_0021: Strings in MATLAB “Check usage of character mathworks.maab.na_0021
functions vector inside MATLAB Function
block” (Simulink Check)
na_0022: Recommended “Check usage of recommended mathworks.maab.na_0022
patterns for Switch/Case patterns for Switch/Case
statements statements” (Simulink Check)
na_0024: Shared data in “Check MATLAB code for global mathworks.maab.na_0024
MATLAB functions variables” (Simulink Check)
na_0025: MATLAB Function No check
header
na_0031: Definition of default “Check usage of enumerated mathworks.maab.na_0031
enumerated value values” (Simulink Check)
na_0034: MATLAB Function “Check input and output mathworks.maab.na_0034
block input/output settings settings of MATLAB Functions”
(Simulink Check)
na_0036: Default variant “Check use of default variants” mathworks.maab.na_0036
(Simulink Check)
na_0037: Use of single variable “Check use of single variable mathworks.maab.na_0037
for variant condition variant conditionals” (Simulink
Check)
na_0039: Limitation on Simulink “Check use of Simulink in mathworks.maab.na_0039
functions in Chart blocks Stateflow charts” (Simulink
Check)
na_0042: Usage of Simulink “Check usage of Simulink mathworks.jmaab.na_0042
functions function in Stateflow” (Simulink
Check)
1-16
Model Advisor Checks for JMAAB Modeling Guidelines
In the Model Advisor, JMAAB checks are organized by guideline version. To access the checks, select:
• JMAAB v5.1 Checks — Checks for version 5.1 of the JMAAB modeling guidelines.
• JMAAB v6.0 Checks — Checks for version 6.0 of the JMAAB modeling guidelines.
• By Task and choose:
• Modeling Standards for JMAAB v5.1 — Checks for version 5.1 of the JMAAB modeling
guidelines.
• Modeling Standards for JMAAB v6.0 — Checks for version 6.0 of the JMAAB modeling
guidelines.
Several modeling guidelines have changed between versions of publication JMAAB Control Algorithm
Modeling Guidelines - Using MATLAB, Simulink, and Stateflow, resulting in new Model Advisor
checks. New check IDs for version 6.0 are in the format mathworks.jmaab_v6.<guideline ID>.
For all other checks, a single Model Advisor check is applicable for both modeling guideline versions.
Guidelines that do not have corresponding Model Advisor checks are identified by using:
• No check — Indicates that the guideline can be checked by using a Model Advisor check, however,
the check does not currently exist.
• Not checkable — Indicates that it is not possible to verify compliance to this guideline by using a
Model Advisor check.
• For version 5.1, see Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and
Stateflow
• For version 6.0, see Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and
Stateflow
1-17
1 Introduction
1-18
Model Advisor Checks for JMAAB Modeling Guidelines
1-19
1 Introduction
1-20
Model Advisor Checks for JMAAB Modeling Guidelines
1-21
1 Introduction
1-22
Model Advisor Checks for JMAAB Modeling Guidelines
1-23
1 Introduction
1-24
Model Advisor Checks for JMAAB Modeling Guidelines
1-25
1 Introduction
1-26
Model Advisor Checks for JMAAB Modeling Guidelines
1-27
1 Introduction
1-28
Model Advisor Checks for JMAAB Modeling Guidelines
1-29
1 Introduction
1-30
Model Advisor Checks for JMAAB Modeling Guidelines
1-31
1 Introduction
See Also
• For more information on Reserved MATLAB words, Built-in MATLAB functions and MATLAB
keywords, refer Appendix C.
1-32
2
Naming Conventions
General Conventions
2-2
ar_0001: Usable characters for file names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f, g
• JMAAB — a, b, c, d, e, f, g
MATLAB Versions
All
Rule
Sub ID a
Line breaks, single-byte spaces, double-byte characters, and control characters shall not be used. File
types that are checked for model and MATLAB files shall be set in the project settings.
Custom Parameter
File (extension)
Example — Incorrect
Sub ID b
File (extension)
2-3
2 Naming Conventions
Example — Incorrect
001_JMAABModel.slx
Sub ID c
File (extension)
Example — Incorrect
_JMAABModel.slx
Sub ID d
File (extension)
Example — Incorrect
MABModel_.slx
Sub ID e
File (extension)
Example — Incorrect
JMAAB__Model.slx
Sub ID f
The file name shall not consist solely of a single reserved MATLAB word.
Custom Parameter
File (extension)
Example — Incorrect
ans.slx, double.slx
Sub ID g
File (extension)
2-4
ar_0001: Usable characters for file names
Example — Incorrect
Files with the same name are saved to the folder that goes through the MATLAB path.
Rationale
Sub IDs a, b, c, f:
• Readability is impaired.
• Deviation from the rule can cause unexpected issues.
Sub IDs d, e
• Readability is impaired.
Sub ID g:
• If there are multiple files with the same name, the one higher on the path is loaded. As a result,
unnecessary files might be included.
• Readability is impaired.
• Deviation from the rule can cause unexpected issues.
Verification
Model Advisor check: “Check file names” (Simulink Check)
Last Changed
R2020a
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Version History
Introduced in R2020a
2-5
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f
• JMAAB — a, b, c, d, e, f
MATLAB Versions
All
Rule
Sub ID a
Line breaks, single-byte spaces, double-byte characters, and control characters shall not be used.
Custom Parameter
Sub ID b
2-6
ar_0002: Usable characters for folder names
Example — Incorrect
Sub ID c
Sub ID d
Sub ID e
Sub ID f
The folder name shall not consist solely of a single reserved MATLAB word.
Custom Parameter
2-7
2 Naming Conventions
Example — Incorrect
Rationale
Sub IDs a, b, c, d, e, f:
• Readability is impaired.
• Deviation from the rule can cause unexpected issues.
Verification
Model Advisor check: “Check folder names” (Simulink Check)
Last Changed
R2024b
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Version History
Introduced in R2020a
2-8
jc_0241: Length restriction for model file names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Model file name length shall be a maximum of 63 characters (not including dots and extension).
Custom Parameter
Rationale
Sub ID a:
• Possible that a long file name cannot be referred to in the model reference.
Verification
Model Advisor check: “Check length of model file name” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
2-9
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Rationale
Sub ID a:
• Possible that the full path name cannot be display in the user interface.
Verification
Model Advisor check: “Check length of folder name at every level of model path” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
2-10
Content Conventions
Content Conventions
2-11
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f
• JMAAB — a, b, c, d, e, f
MATLAB Versions
All
Rule
Sub ID a
Line breaks, single-byte spaces, double-byte characters, and control characters shall not be used.
Custom Parameter
Not Applicable
Example — Incorrect
2-12
jc_0201: Usable characters for subsystem names
Sub ID b
Not Applicable
Example — Incorrect
Sub ID c
Not Applicable
Example — Incorrect
Sub ID d
Not Applicable
2-13
2 Naming Conventions
Example — Incorrect
Sub ID e
Not Applicable
Example — Incorrect
Sub ID f
A structural subsystem shall not consist solely of a single reserved MATLAB word.
Custom Parameter
Not Applicable
Example — Incorrect
Rationale
Sub IDs a, b, f:
Sub IDs c, d, e:
• May not be able to generate code using the configured structural subsystem name.
Verification
Model Advisor check: “Check subsystem names” (Simulink Check)
2-14
jc_0201: Usable characters for subsystem names
Last Changed
R2020a
See Also
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
2-15
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f
• JMAAB — a, b, c, d, e, f
MATLAB Versions
All
Rule
Sub ID a
Only these character types shall be used for basic block names:
Line breaks and single-byte spaces shall not be permitted when adding a new block name. However,
they shall be permitted when used initially as a block name that is saved in the Simulink library.
Not Applicable
Example — Correct
2-16
jc_0231: Usable characters for block names
Example — Incorrect
Sub ID b
Not Applicable
Example — Incorrect
Sub ID c
Not Applicable
2-17
2 Naming Conventions
Example — Incorrect
Sub ID d
Not Applicable
Example — Incorrect
Sub ID e
Not Applicable
Example — Incorrect
Sub ID f
Basic block names shall not consist solely of a single reserved MATLAB word.
Exception
Not Applicable
2-18
jc_0231: Usable characters for block names
Example — Incorrect
Rationale
Sub IDs a, b:
• Deviation from the rule can make it difficult to maintain the integrity of the model and code.
Sub IDs c, e:
• Readability is impaired.
Sub IDs d:
• Readability is impaired.
• Underscores can be used to separate words. However, they are typically used as word breaks and
can cause misunderstanding in the description.
Sub IDs f:
• Readability is impaired.
• Deviation from the rule can cause unexpected issues.
Verification
Model Advisor check: “Check character usage in block names” (Simulink Check)
Last Changed
R2020a
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Version History
Introduced in R2020a
2-19
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f
• JMAAB — a, b, c, d, e, f
MATLAB Versions
All
Rule
Sub ID a
Only these character types shall be used in Inport and Outport block names:
Line breaks, single-byte spaces, double-byte characters, and control characters shall not be used.
Custom Parameter
Not Applicable
Example — Incorrect
2-20
jc_0211: Usable characters for Inport blocks and Outport block
Sub ID b
[Inport] and [Outport] block names shall not use numbers at the beginning.
Custom Parameter
Not Applicable
Example — Incorrect
Sub ID c
[Inport] and [Outport] block names shall not use underscores at the beginning.
Custom Parameter
Not Applicable
Example — Incorrect
Sub ID d
[Inport] and [Outport] block names shall not use underscores at the end.
Custom Parameter
Not Applicable
Example — Incorrect
Sub ID e
[Inport] and [Outport] block names shall not use consecutive underscores.
Custom Parameter
Not Applicable
Example — Incorrect
2-21
2 Naming Conventions
Sub ID f
[Inport] and [Outport] block names shall not consist solely of a single reserved MATLAB word.
Custom Parameter
Not Applicable
Example — Incorrect
Rationale
Sub IDs a, b:
• Deviation from the rule can make it difficult to maintain the integrity of the model and code.
Sub IDs c, e:
• Readability is impaired.
Sub IDs d:
• Readability is impaired.
• Underscores can be used to separate words. However, they are typically used as word breaks and
can cause misunderstanding in the description.
Sub IDs f:
• Readability is impaired.
• Deviation from the rule can cause unexpected issues.
Verification
Model Advisor check: “Check port block names” (Simulink Check)
Last Changed
R2020a
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Version History
Introduced in R2020a
2-22
jc_0243: Length restriction for subsystem names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of subsystem names” (Simulink Check)
Last Changed
R2020a
See Also
• “Explore Types of Subsystems”
2-23
2 Naming Conventions
Version History
Introduced in R2020a
2-24
jc_0247: Length restriction for block names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of block names” (Simulink Check)
Last Changed
R2020a
2-25
2 Naming Conventions
Version History
Introduced in R2020a
2-26
jc_0244: Length restriction for Inport and Outport names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of Inport and Outport names” (Simulink Check)
Last Changed
R2020a
2-27
2 Naming Conventions
Version History
Introduced in R2020a
2-28
jc_0222: Usable characters for signal and bus names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f
• JMAAB — a, b, c, d, e, f
MATLAB Versions
All
Rule
Sub ID a
Only these character types shall be used in signal and bus names:
Line breaks, single-byte spaces, double-byte characters, and control characters shall not be used.
Custom Parameter
Not Applicable
Sub ID b
Signal and bus names shall not use numbers at the beginning.
Custom Parameter
Not Applicable
Sub ID c
The signal or bus name shall not use underscores at the beginning.
Custom Parameter
Not Applicable
2-29
2 Naming Conventions
Sub ID d
Signal and bus names shall not use underscores at the end.
Custom Parameter
Not Applicable
Sub ID e
Not Applicable
Sub ID f
Signal and bus names shall not consist solely of a single reserved MATLAB word.
Custom Parameter
Not Applicable
Rationale
Sub IDs a, b:
• Deviation from the rule can make it difficult to maintain the integrity of the model and code.
Sub IDs c, e:
• Readability is impaired.
Sub IDs d:
• Readability is impaired.
• Underscores can be used to separate words. However, they are typically used as word breaks and
can cause misunderstanding in the description.
Sub IDs f:
• Readability is impaired.
• Deviation from the rule can cause unexpected issues.
Verification
Model Advisor check: “Check usable characters for signal names and bus names” (Simulink Check)
Last Changed
R2020a
2-30
jc_0222: Usable characters for signal and bus names
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
• “Signal Basics”
• “Simulink Bus Capabilities”
Version History
Introduced in R2020a
2-31
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Sub ID b
Not Applicable
Sub ID c
The parameter name shall not consist solely of a single reserved MATLAB word.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Readability is impaired.
• Underscores can be used to separate words. However, they are typically used as word breaks and
can cause misunderstanding in the description.
2-32
jc_0232: Usable characters for parameter names
Sub ID b:
• Readability is impaired.
Sub ID c:
• Readability is impaired. Deviation from the rule can cause unexpected issues.
Verification
Model Advisor check: “Check usable characters for parameter names” (Simulink Check)
Last Changed
R2024b
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Version History
Introduced in R2020a
2-33
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
2-34
jc_0245: Length restriction for signal and bus names
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of signal and bus names” (Simulink Check)
Last Changed
R2020a
See Also
• “Model Configuration Parameters”
• “Signal Basics”
• “Simulink Bus Capabilities”
Version History
Introduced in R2020a
2-35
2 Naming Conventions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of parameter names” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
2-36
jc_0795: Usable characters for Stateflow data names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d
• JMAAB — a, b, c, d
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Sub ID b
Not Applicable
Sub ID c
Not Applicable
Sub ID d
Stateflow data {name} shall not consist solely of a single reserved MATLAB word.
2-37
2 Naming Conventions
Custom Parameter
Not Applicable
Rationale
Sub IDs a, b, c, d:
• Readability is impaired.
• Deviation from the rule may result in unintended code behavior.
Verification
Model Advisor check: “Check usable characters for Stateflow data names” (Simulink Check)
Last Changed
R2020a
See Also
• “Add Stateflow Data” (Stateflow)
• “Set Data Properties” (Stateflow)
Version History
Introduced in R2020a
2-38
jc_0796: Length restriction for Stateflow data names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d
• JMAAB — a, b, c, d
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Rationale
Sub ID a:
• Readability is impaired.
• Deviation from the rule can result in unintended code behavior
Verification
Model Advisor check: “Check length of Stateflow data name” (Simulink Check)
Last Changed
R2020a
2-39
2 Naming Conventions
See Also
• “Add Stateflow Data” (Stateflow)
• “Set Data Properties” (Stateflow)
Version History
Introduced in R2020a
2-40
jc_0791: Duplicate data name definitions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Data name definitions shall not be duplicated in the base workspace and model workspace.
Custom Parameter
Not Applicable
Sub ID b
Data names shall not be duplicated in the base workspace and data dictionary (sldd).
Custom Parameter
Sub ID c
Data name definitions shall not be duplicated in the model workspace and data dictionary (sldd).
Custom Parameter
Rationale
Sub IDs a, b, c:
2-41
2 Naming Conventions
Verification
Model Advisor check: “Check duplication of Simulink data names” (Simulink Check)
Last Changed
R2020a
See Also
• “Set Data Properties” (Stateflow)
• “Add Stateflow Data” (Stateflow)
• “Model Reference Data Storage”
Version History
Introduced in R2020a
2-42
jc_0792: Unused Data
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
The data dictionary (sldd) shall define only the data that is used in the Simulink or Stateflow Coder™
model.
Custom Parameter
Sub ID b
The model workspace shall define only the data that is used in the Simulink or Stateflow model.
Custom Parameter
Not Applicable
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check unused data in Simulink Model” (Simulink Check)
2-43
2 Naming Conventions
Last Changed
R2020a
See Also
• “Model Reference Data Storage”
Version History
Introduced in R2020a
2-44
jc_0700: Unused data in Stateflow block
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Configuration parameter Unused data, events, messages, and functions shall be set to Warning
or Error to prevent unused Stateflow data, events, and messages in the Stateflow block.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
2-45
2 Naming Conventions
Rationale
Sub ID a:
• Unused data and events in the Stateflow block can affect maintainability and reusability.
• Affects code as a declarative statement concerning unused data is inserted into the generated
code.
Verification
Model Advisor check: “Check for unused data in Stateflow Charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Data, Events, and Messages” (Stateflow)
• “View Differences Between Stateflow Messages, Events, and Data” (Stateflow)
• “Manage Symbols in the Stateflow Editor” (Stateflow)
Version History
Introduced in R2020a
2-46
na_0019: Restricted variable names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
Reserved C variable names shall not be used as variable names in MATLAB code. For example, avoid
using const, TRUE, FALSE, infinity, nil, double, single, or enum in MATLAB code.
Custom Parameter
Not Applicable
Sub ID b
Variable names that conflict with MATLAB functions, such as conv, shall not be used.
Custom Parameter
Not Applicable
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check usage of restricted variable names” (Simulink Check)
2-47
2 Naming Conventions
Last Changed
R2020a
See Also
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
• “Integrate MATLAB Functions in a Stateflow Charts” (Stateflow)
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
Version History
Introduced in R2020a
2-48
3
Simulink
Configuration Parameters
3-2
jc_0011: Optimization parameters for Boolean data types
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Configuration parameter Implement logic signals as Boolean data (vs. double) shall be selected
so that optimization parameters are activated for logic signals.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Using Boolean data can reduce RAM capacity when using C code.
Verification
Model Advisor check: “Check Implement logic signals as Boolean data (vs. double)” (Simulink Check)
Last Changed
R2020a
3-3
3 Simulink
See Also
• “Signal Basics”
Version History
Introduced in R2020a
3-4
jc_0642: Integer rounding mode setting
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When block parameter Integer rounding mode is set to Simplest, configuration parameter
Production hardware signed integer division rounds to shall be set to Floor or Zero.
Custom Parameter
Not Applicable
Example — Correct
Block parameter Integer rounding mode is set to Simplest and configuration parameter
Production hardware signed integer division rounds to is set to Zero.
3-5
3 Simulink
Example — Incorrect
3-6
jc_0642: Integer rounding mode setting
Rationale
Sub ID a:
Verification
Model Advisor check: “Check Signed Integer Division Rounding mode” (Simulink Check)
Last Changed
R2024b
See Also
• Signed integer division rounds to
Version History
Introduced in R2020a
3-7
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Sub ID b
Not Applicable
Sub ID c
• Wrap on overflow
• Saturate on overflow
Not Applicable
3-8
jc_0806: Detecting incorrect calculation results
Rationale
Sub IDs a, b, c:
Verification
Model Advisor check: “Check diagnostic settings for incorrect calculation results” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-9
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
• Algebraic loop
• Minimize algebraic loop
• “Multitask data transfer”
• “Inf or NaN block output”
• “Duplicate data store names”
• Unconnected block input ports
• Unconnected block output ports
• Unconnected line
• Unspecified bus object at root Outport block
• Element name mismatch
• (R2017a and earlier) Mux blocks used to create bus signals
• (R2012a and earlier) Invalid function-call connection
Custom Parameter
Not Applicable
Rationale
Sub ID a:
3-10
jc_0021: Model diagnostic settings
Verification
Model Advisor check “Check model diagnostic parameters” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-11
3 Simulink
Diagram Appearance
3-12
na_0004: Simulink model appearance settings
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Simulink model appearance settings shall conform with the project settings.
Custom Parameter
Display option
Example — View Options
On the Simulink toolstrip, these parameters are available in the Modeling tab, under Environment.
Parameter Setting
Model Browser Deselect Model Browser.
Status Bar Select Status Bar.
Toolstrip Select Toolstrip.
Zoom Select Zoom (Normal View 100%).
On the Simulink toolstrip, these parameters are available in the Debug tab, under Information
Overlays.
Parameter Setting
Library Links Select Hide All Links.
Linearization Indicators Select Linearization Indicators.
3-13
3 Simulink
Parameter Setting
Ref. Model I/O Mismatch Deselect Ref. Model I/O Mismatch.
Ref. Model Version Deselect Ref. Model Version.
Sample Time Colors Deselect Colors.
Execution Order Deselect Execution Order.
On the Simulink toolstrip, these parameters are available in the Format tab.
Parameter Setting
Background color Select white option from the Background list.
Foreground color Select black option from the Foreground list.
To access the parameter below, On the Simulink toolstrip, open Simulink Coder from Apps, select C
Code tab and choose Code Interface.
Parameter Setting
Storage Class Indicator Deselect Storage Class Indicator.
On the Simulink toolstrip, these parameters are available in the Debug tab, under Information
Overlays.
Parameter Setting
Base Data Types Deselect Base Data Types.
Alias Data Types Deselect Alias Data Types.
Signal Dimensions Deselect Signal Dimensions.
Testpoint Select Test Point.
Logging and Viewer indicators Select Logging & Viewers.
Nonscalar Signals Select Nonscalar Signals.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for Simulink diagrams using nonstandard display attributes” (Simulink
Check)
3-14
na_0004: Simulink model appearance settings
Last Changed
R2020a
See Also
• MISRA AC SLSF 023A
• “Mapping from Simulink Editor to the Simulink Toolstrip”
Version History
Introduced in R2020a
3-15
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d
• JMAAB — a, b, c, d
MATLAB Versions
All
Rule
Sub ID a
Block name font and font style shall conform with the project settings.
Signal name font and font style shall conform with the project settings.
Custom Parameter
Font
Font style
Sub ID b
Block name font size shall conform with the project settings.
Signal name font size shall conform with the project settings
Custom Parameter
Font size
Sub ID c
State labels and box name font and font style shall conform with the project settings.
Transition labels and comment font and font style shall conform with the project settings.
Custom Parameter
Font
3-16
db_0043: Model font and font size
Font style
Sub ID d
State labels and box name font size shall conform with the project settings.
Transition labels and comment font size shall conform with the project settings.
Custom Parameter
Font size
Rationale
Sub IDs a, c:
Sub IDs b, d:
Verification
Model Advisor check: “Check model font settings” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-17
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Blocks shall be sized so that the block icon is visible and recognizable.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
The block is too small so the icon is neither visible nor recognizable.
3-18
jm_0002: Block resizing
Rationale
Sub ID a:
• When a block is too small, the text and symbol displayed by the icon can be difficult to see, which
impairs readability.
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
Last Changed
R2020a
See Also
• “Configure Model Layout”
Version History
Introduced in R2020a
3-19
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
3-20
db_0142: Position of block names
Rationale
Sub ID a:
• Consistent placement of the block name improves model readability because it is easier to
determine which name corresponds to the block.
Verification
Model Advisor check: “Check whether block names appear below blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-21
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Block names shall be hidden for blocks that meet either of these criteria:
For blocks that do not meet the criteria, their name shall be displayed.
Custom Parameter
3-22
jc_0061: Display of block names
Rationale
Sub ID a:
Verification
Model Advisor check: “Check the display attributes of block names” (Simulink Check)
Last Changed
R2020a
See Also
• MISRA AC SLSF 026A
Version History
Introduced in R2020a
3-23
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Block annotation shall display block parameters that are defined by the project.
Custom Parameter
Block parameters
Example — Correct
Example — Incorrect
3-24
db_0140: Display of block parameters
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for display of block parameter” (Simulink Check)
Last Changed
R2020a
See Also
• MISRA AC SLSF 026E
• “Set Block Annotation Properties”
Version History
Introduced in R2020a
3-25
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Layers that require a description are defined (by function and layer type) in the project.
Custom Parameter
Sub ID b
3-26
jc_0603: Model description
Custom Parameter
Rationale
Sub ID a:
• When a description is not included, the readability of the control specifications is reduced.
Usability, maintainability, and portability also decreases.
Sub ID b:
Verification
Model Advisor check: “Check Model Description” (Simulink Check)
Last Changed
R2020a
See Also
• Sub ID a and b, see MISRA AC SLSF 022
Version History
Introduced in R2020a
3-27
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
3-28
jc_0604: Using block shadow
Rationale
Sub ID a:
• Difficult to determine if a port exists because it is hidden by the shading, which impairs
readability.
Verification
Model Advisor check: “Check if blocks are shaded in the model” (Simulink Check)
Last Changed
R2020a
See Also
• “Common Block Properties”
• “Set Block Parameter Values”
Version History
Introduced in R2020a
3-29
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
The model shall not have signal lines that are not connected.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-30
db_0081: Unconnected signals and blocks
Sub ID b
The model shall not have subsystems or basic blocks that are not connected.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Rationale
Sub IDs a, b:
• Unconnected lines can have adverse effects, such as simulation errors or failure to generate code.
Verification
Model Advisor check: “Check for unconnected signal lines and blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Basics”
• “Explore Types of Subsystems”
3-31
3 Simulink
Version History
Introduced in R2020a
3-32
db_0032: Signal line connections
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Signal lines shall not split into more than two sub lines at a single branching point.
Custom Parameter
Not Applicable
Example — Correct
3-33
3 Simulink
Example — Incorrect
Sub ID b
Signal lines shall be resized vertically or horizontally as required for the model layout.
Custom Parameter
Not Applicable
Sub ID c
Custom Parameter
Not Applicable
Example — Correct
3-34
db_0032: Signal line connections
Example — Incorrect
Rationale
Sub ID a:
Sub ID b:
Sub ID c:
Verification
Model Advisor check: “Check signal line connections” (Simulink Check)
Last Changed
R2024b
See Also
• “Signal Basics”
3-35
3 Simulink
Version History
Introduced in R2020a
3-36
db_0141: Signal flow in Simulink models
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
3-37
3 Simulink
Example — Correct
3-38
db_0141: Signal flow in Simulink models
Example — Incorrect
Sub ID b
Not Applicable
3-39
3 Simulink
Example — Correct
Example — Incorrect
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check signal flow in model” (Simulink Check)
Last Changed
R2024b
3-40
db_0141: Signal flow in Simulink models
See Also
• “Signal Basics”
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-41
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When a Delay is used in a feedback loop, the output can be to the left.
Custom Parameter
Not Applicable
Example — Correct
The model is arranged so that the output is to the right. The output of the Delay block is to the left.
3-42
jc_0110: Direction of block
Example — Incorrect
Rationale
Sub ID a:
• Signal flow can be difficult to understand if the direction of the signals is not consistent.
Verification
Model Advisor check: “Check block orientation” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-43
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
When a two-way signal connection exists between two structural subsystems (A and B), each
direction shall be connected to at least one signal line.
Exception
Using Goto and From blocks to create buses or connect signals to a Merge block.
Custom Parameter
Not Applicable
3-44
jc_0171: Clarification of connections between structural subsystems
Example — Correct
Example — Incorrect
Sub ID b
Signals that are not used within a structural subsystem shall be input to a structural subsystem.
These signals shall not be output to other structural subsystems or basic blocks.
Custom Parameter
Not Applicable
3-45
3 Simulink
Example — Correct
Example — Incorrect
Signals that are not used in the subsystem are connected to avoid crossing of signal lines.
3-46
jc_0171: Clarification of connections between structural subsystems
Rationale
Sub ID a:
Sub ID b:
Verification
Model Advisor check: “Check connections between structural subsystems” (Simulink Check)
Last Changed
R2020a
3-47
3 Simulink
See Also
• “Signal Basics”
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-48
jc_0602: Consistency in model element names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
These names shall match when they are directly connected by using signal lines.
Exceptions
A signal line that connects to one of the following subsystem types can have a name that differs from
that of the subsystem port label:
When a combination of Inport, Outport, and other blocks have the same name, use a suffix or prefix
for the Inport and Outport blocks. Any prefix or suffix can be used for ports, but they must be
consistent. For example, the Inport block uses “in” and Outport block uses “out”.
Note Inport and Outport blocks must have different names and signal names.
3-49
3 Simulink
Custom Parameter
Not Applicable
Example — Correct
Names of model elements that connect directly to signal lines are consistent.
Example — Incorrect
Inconsistent names for model elements that connect directly to signal lines.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for consistency in model element names” (Simulink Check)
Last Changed
R2020a
See Also
• “Manage Signal Lines”
3-50
jc_0602: Consistency in model element names
Version History
Introduced in R2020a
3-51
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a1/a2/a3/a4, b1/b2/b3/b4
MATLAB Versions
All
Rule
Sub ID a1
The name of the conditional input block at the destination shall include the name of the block at the
origin of the trigger signal
Custom Parameter
Not Applicable
Example — Correct
3-52
jc_0281: Trigger signal names
Example — Incorrect
Sub ID a2
The name of the conditional subsystem at the destination shall include the name of the block at the
origin of the trigger signal.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID a3
The name of the conditional input block at the destination shall include the name of the trigger
signal.
Custom Parameter
Not Applicable
3-53
3 Simulink
Example — Correct
Example — Incorrect
Sub ID a4
The name of the conditional subsystem at the destination shall include the name of the trigger signal.
Custom Parameter
Not Applicable
Example — Correct
3-54
jc_0281: Trigger signal names
Example — Incorrect
Sub ID b1
The name of the Stateflow block event at the destination shall include the name of the block at the
origin of the trigger signal.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-55
3 Simulink
Sub ID b2
The name of Stateflow Chart at the destination shall include the name of the block at the origin of the
trigger signal.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID b3
The name of the Stateflow block event at the destination shall include the name of the trigger signal.
Custom Parameter
Not Applicable
3-56
jc_0281: Trigger signal names
Example — Correct
Example — Incorrect
Sub ID b4
The name of the trigger signal and the Stateflow Chart name at the destination must include the
same name. The name of the Chart block at the destination shall include the name of the trigger
signal.
Custom Parameter
Not Applicable
Example — Correct
3-57
3 Simulink
Example — Incorrect
Rationale
Sub ID a1, a2, a3, a4, b1, b2, b3, b4:
Verification
Model Advisor check: “Check trigger signal names” (Simulink Check)
Last Changed
R2020a
See Also
• Sub ID a1, a2, a3, a4, see MISRA AC SLSF 026C
• “Signal Basics”
• “Use Events to Execute Charts” (Stateflow)
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-58
db_0143: Usable block types in model hierarchy
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Model levels shall use only the block types that are defined for the layer type. Clearly defined layer
types restrict the number of blocks that can be used.
Block restrictions:
• (R2011a and earlier) Enable block cannot be used at the root level of the model.
• Action ports are not permitted at the root level of a model.
Layer restrictions:
• Data flow layers that are used for basic blocks only.
• Other than data flow layers, layers can include blocks that are used for structural subsystems and
all other layers.
• Inport
• Outport
• Mux
• Demux
• Bus Selector
• Bus Creator
• Selector
• Ground
3-59
3 Simulink
• Terminator
• From
• Goto
• Merge
• Unit Delay
• Rate Transition
• Data Type Conversion
• Data Store Memory
• If
• Switch Case
• Function-Call Generator
• Function-Call Split
• Inport Shadow
Custom Parameter
Layer type
Block type
Rationale
Sub ID a:
• Readability is impaired when subsystems and basic blocks are used in the same layer.
Verification
Model Advisor check: “Check for mixing basic blocks and subsystems” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-60
db_0144: Use of subsystems
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Blocks in a Simulink diagram shall be grouped together into subsystems based on functional
decomposition of the algorithm, or portion thereof, represented in the diagram. Blocks can also be
grouped together based on behavioral variants or timing.
Avoid grouping blocks into subsystems primarily for the purpose of saving space in the diagram. Each
subsystem in the diagram should represent a unit of functionality that is required to accomplish the
purpose of the model or submodel.
Not Applicable
Example — Correct
3-61
3 Simulink
Example — Incorrect
Sub ID b
A virtual subsystem shall be used when processing order and code generation does not need to be
taken into consideration.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
3-62
db_0144: Use of subsystems
• Avoid grouping blocks into subsystems primarily for the purpose of saving space in the diagram.
• It can be difficult to reuse the subsystem.
Sub ID b:
• As atomic subsystems are considered a single process that influences processing order and code
optimization, they can be misinterpreted when used other than as intended.
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
Last Changed
R2020a
See Also
• Subsystem
Version History
Introduced in R2020a
3-63
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Delay block in feedback loops across subsystems shall reside in the hierarchy that describes the
feedback loop.
Custom Parameter
Not Applicable
Example — Correct
Delay block resides in the hierarchy that describes the feedback loop.
3-64
jc_0653: Delay block layout in feedback loops
Example — Incorrect
Delay block resides in a subsystem that is nested within the hierarchy which describes the feedback
loop.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for avoiding algebraic loops between subsystems” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-65
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
• To File
• To Workspace
• Stop Simulation
Consider using signal logging and the Viewers and Generators Manager for data logging and viewing
requirements. (R2019b and later) To log and manage the signal, click the Simulation tab and, under
the Prepare gallery, select the appropriate tool.
Custom Parameter
Not Applicable
Rationale
Sub ID a
3-66
hd_0001: Prohibited Simulink sinks
Verification
Model Advisor check: “Check for prohibited sink blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Viewers and Generators Manager”
Version History
Introduced in R2020a
3-67
3 Simulink
Signal
3-68
na_0010: Usage of vector and bus signals
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b, c, d
MATLAB Versions
All
Rule
Sub ID a
Mux and Demux blocks shall be used when generating and decomposing vectors.
Custom Parameter
Not Applicable
Sub ID b
Not Applicable
Sub ID c
Bus Creator and Bus Selector blocks shall be used when generating and decomposing buses.
Custom Parameter
Not Applicable
Sub ID d
Not Applicable
3-69
3 Simulink
Rationale
Sub IDs a, b, c, d:
• Prevents issues that are caused by combining vector and bus signals.
Verification
Model Advisor check: “Check usage of vector and bus signals” (Simulink Check)
Last Changed
R2021a
See Also
• “Signal Basics”
• “Signal Types”
• “Specify Bus Properties with Bus Objects”
• “Bus-Capable Blocks”
Version History
Introduced in R2020a
3-70
jc_0008: Definition of signal names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Signal names shall be defined for signal lines that output from important blocks. The signal name
shall be provided once, at the origin of the signal line.
Note An important block is defined by the system input and output of meaningful results, not by its
type.
Custom Parameter
3-71
3 Simulink
Example — Incorrect
Rationale
Sub ID a:
• Defining the signal name and displaying the label for the output of meaningful results from
important blocks improves the readability of the model.
Verification
Model Advisor check: “Check definition of signal labels” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Basics”
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-72
jc_0009: Signal name propagation
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
When defining the signal name for a signal that extends across a hierarchy, signal property Show
propagated signals shall be selected so that propagated signal names are displayed.
However, when one of the following conditions is met, do not select Show propagated signals:
Custom Parameter
Not Applicable
Example — Correct
3-73
3 Simulink
Example — Incorrect
Show propagated signals is not selected, therefore signal names are not displayed.
Signals that connect to Bus Creator and Outport blocks do not have names, but Show propagated
signals is selected for signals that connect to Subsystem and Outport blocks.
3-74
jc_0009: Signal name propagation
Signals that connect to Bus Creator and Outport blocks have names, but signals that connect to
Subsystem and Outport blocks also have names.
Sub ID b
Signal property Show propagated signals shall be selected for these blocks so that propagated
signal names of the signal output are displayed:
• From
• Signal Specification
• Function-Call Split[
Custom Parameter
Not Applicable
Example — Correct
3-75
3 Simulink
Signals that connect to Inport and Goto blocks do not have names, therefore Show propagated
signals does not need to be selected.
3-76
jc_0009: Signal name propagation
Signals that connect to Inport and Goto blocks do not have names, therefore signals that connect to
From and Gain blocks can be left unnamed.
Example — Incorrect
Signals that connect to Inport and Goto blocks do not have names, but Show propagated signals is
selected for signals that connect to From and Gain blocks.
Regardless of whether signals are propagated, Show propagated signals is not selected
Signals that connect to Inport and Goto blocks have names, but signals that connect to From and
Gain blocks are named.
3-77
3 Simulink
Signals that connect to Gain and Signal Specification blocks do not have names, but Show
propagated signals is selected for signals that connect to Signal Specification and Outport blocks.
Regardless of whether signals are propagated, Show propagated signals is not selected.
Signals that connect to Gain and Signal Specification blocks have names, but signals that connect to
Signal Specification and Outport blocks also have names.
Signals that connect to Function-Call Generator and Function-Call Split blocks do not have names,
but Show propagated signals is selected for signals that connect to Function-Call Split and
Function-Call Subsystem blocks.
Regardless of whether signals are propagated, Show propagated signals is not selected.
3-78
jc_0009: Signal name propagation
Signals that connect to Function-Call Generator and Function-Call Split blocks have names and
signals that connect to Function-Call Split and Function-Call Subsystem blocks are also named.
Sub ID c
When propagated signal names does not exist Show propagated signals shall not be selected.
Example — Incorrect
Signals that connect to Bus Creator and Outport blocks do not have names, but Show propagated
signals is selected for signals that connect to Subsystem and Outport blocks.
Rationale
Sub IDs a, b:
3-79
3 Simulink
Sub ID c:
Verification
Model Advisor check: “Check signal name propagation” (Simulink Check)
Last Changed
R2024b
See Also
• “Signal Basics”
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-80
db_0097: Position of labels for signals and buses
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Signal line labels and bus labels shall be positioned below signal lines.
Custom Parameter
Not Applicable
Example — Correct
Signal line labels and bus labels are below signal lines.
Example — Incorrect
Signal line labels and bus labels are above the signal line.
3-81
3 Simulink
Sub ID b
Signal line labels and bus labels shall be positioned at the origin of the connection.
Custom Parameter
Not Applicable
Example — Correct
Signal line labels and bus labels are positioned at the origin of the signal line connection.
Example — Incorrect
Signal line labels and bus labels are positioned at the destination of the signal line connection.
Rationale
Sub ID a, b:
3-82
db_0097: Position of labels for signals and buses
• Consistent label position prevents confusion with corresponding labels, signal lines, and buses,
which improves the readability of the model.
Verification
Model Advisor check: “Check position of signal labels” (Simulink Check)
Last Changed
R2024b
See Also
• “Signal Basics”
• “Signal Lines”
• “Simulink Bus Capabilities”
Version History
Introduced in R2020a
3-83
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
A label shall be displayed on the signal line originating from these blocks:
• Inport
• From (see exception)
• Subsystem or Stateflow Chart (see exception)
• Bus Selector (the tool forces this to happen)
• Demux
• Selector
• Data Store Read (see exception)
• Constant (see exception)
Exception
When the signal label is visible in the originating block icon display, the signal does not need not to
have the label displayed unless the signal label is needed elsewhere due to a destination-based rule.
Custom Parameter
Not Applicable
Sub ID b
A label shall be displayed on a signal line that connects (either directly or by way of a basic block that
performs a non-transformative operation) to these destination blocks:
3-84
na_0008: Display of labels on signals
• Outport
• Goto
• Data Store Write
• Bus Creator
• Mux
• Subsystem
• Stateflow Chart
Custom Parameter
Not Applicable
Rationale
Sub ID a:
Sub ID b:
Verification
Model Advisor check: “Check signal line labels” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Basics”
• “Manage Signal Lines”
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-85
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
When a label is displayed for a signal, the following rules define whether that label is created there
(entered directly on the signal) or propagated from its true source (inherited from elsewhere in the
model by using the < character).
Exceptions
When the nested subsystem is a library subsystem, a label can be entered on the signal coming from
the Inport block to accommodate reuse of the library block.
When the connection originates from the output of a library subsystem block, a new label can be
entered on the signal to accommodate readability.
Custom Parameter
Not Applicable
3-86
na_0009: Entry versus propagation of signal labels
Rationale
Sub ID a:
• The result of executing a MATLAB command is reflected in the code, which makes consistency
between the model and code difficult to maintain.
Verification
Model Advisor check: “Check for propagated signal labels” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Basics”
• “Manage Signal Lines”
• “Signal Label Propagation”
• “Explore Types of Subsystems”
Version History
Introduced in R2020a
3-87
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
• Operation expressions
• Data type conversion
• Selection of rows or columns
• MATLAB commands
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Operation expressions, data type conversion, or row or column selection become a magic number
in generated code, which makes consistency between the model and code difficult to maintain.
Adjusting parameters also becomes difficult.
• Describing the calculation formula within the block decreases readability.
• The result of executing a MATLAB command is reflected in the code, which makes consistency
between the model and code difficult to maintain.
Verification
Model Advisor check: “Check usage of tunable parameters in blocks” (Simulink Check)
3-88
db_0110: Block parameters
Last Changed
R2020a
Version History
Introduced in R2020a
3-89
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
3-90
db_0112: Usage of index
Example — Incorrect
Sub ID a2
Not Applicable
Example — Correct
Example — Incorrect
A uniform index mode is not used (same as the incorrect example for sub ID a1).
3-91
3 Simulink
Rationale
Sub IDs a1, a2
Verification
Model Advisor check: “Check Indexing Mode” (Simulink Check)
Last Changed
R2020a
See Also
• Index Vector
Version History
Introduced in R2020a
3-92
jc_0645: Parameter definition for calibration
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Block parameters that are targets of calibration shall be defined as named constants. Examples of
parameters that are outside of the calibration target include:
Not Applicable
Example — Correct
Example — Incorrect
3-93
3 Simulink
Rationale
Sub ID a:
• A literal constant in the model will propagate as a literal constant in the generated code, making
calibration impossible.
Verification
Model Advisor check: “Check if tunable block parameters are defined as named constants” (Simulink
Check)
Last Changed
R2020a
See Also
• “Set Block Parameter Values”
Version History
Introduced in R2020a
3-94
jc_0641: Sample time setting
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
• Inport block
• Outport block
• Atomic subsystem
• Blocks with state variables, such as Unit Delay and Memory
• Signal conversion blocks, such as Data Type Conversion and Rate Transition
• Blocks that do not have external inputs, such as Constant
• Stateflow charts
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Discrepancies can occur in the processing of the model because of different simulation times.
• Maintainability of the model deteriorates when a specific sample time is set for each block
individually.
3-95
3 Simulink
Verification
Model Advisor check: “Check for sample time setting” (Simulink Check)
Last Changed
R2020a
See Also
• “What Is Sample Time?”
• “Explore Types of Subsystems”
• “Construct and Run a Stateflow Chart” (Stateflow)
Version History
Introduced in R2020a
3-96
jc_0643: Fixed-point setting
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When block parameter Data type is a set to fixdt (fixed-point) and Scaling is set to Slope and
bias, parameter Bias shall be set to 0.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of fixed-point data type with non-zero bias” (Simulink Check)
Last Changed
R2020a
3-97
3 Simulink
See Also
• “Specify Fixed-Point Data Types”
• “Specify Data Types Using Data Type Assistant”
• “Scaling, Precision, and Range”
Version History
Introduced in R2020a
3-98
jc_0644: Type setting
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The data type shall not be set by using a block or Stateflow data when the data type is set by a data
object.
Exceptions
Custom Parameter
Not Applicable
Example — Correct
3-99
3 Simulink
Rationale
Sub ID a:
• When the data type is set in a block and it differs from the type setting in the data object, it can be
difficult to determine which setting is correct. This can impair readability.
• When the type is set in the block, maintainability is affected when the signal line type changes.
Exceptions
• When block structures are identical, differences between input/output data type can result in
different C source code that is not reusable. For reusable functions, data types of input/output
blocks should be specified at the subsystem level.
• The Data Type Conversion block is used to explicitly set the data type.
• When the data type is fixdt (fixed-point), data type must be set individually because each block
can have different data points. In this scenario, it is impossible to use only the data object to set
the data type.
3-100
jc_0644: Type setting
For example, Output data type is set to boolean by default. It is generally expected that the
result of a logical operation boolean, eliminating the need to adjust inheritance settings. Given
that the expected type is preconfigured in blocks set by default in this manner, readability and
maintainability are not compromised.
Example — Correct
Type is set for the data object but not the block.
Example — Incorrect
Type is set for both the data object and the block.
Verification
Model Advisor check: “Check type setting by data objects” (Simulink Check)
Last Changed
R2024b
3-101
3 Simulink
See Also
• “About Data Types in Simulink”
• “Simulink Functions Overview”
Version History
Introduced in R2020a
3-102
Conditional Subsystem Relations
3-103
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
3-104
db_0146: Block layout in conditional subsystems
Example — Incorrect
Sub ID b
• For Each
• For Iterator
• While Iterator
Custom Parameter
Location layout
Rationale
Sub IDs a, b:
• Unifying the internal and external layout of the conditional subsystem improves readability of the
model.
Verification
Model Advisor check: “Check position of conditional blocks and iterator blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Conditionally Executed Subsystems Overview”
3-105
3 Simulink
Version History
Introduced in R2020a
3-106
jc_0640: Initial value settings for Outport blocks in conditional subsystems
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The initial condition shall be defined on an Outport block when both of these conditions are met for a
conditional subsystem:
• Includes a block with initial conditions (i.e. Constant and Delay blocks)
• Connects to Outport block
When the output signal from a conditional subsystem is connected to a Merge block, the initial
condition shall be defined on the Merge block.
Custom Parameter
Not Applicable
Example — Correct
3-107
3 Simulink
Example — Incorrect
3-108
jc_0640: Initial value settings for Outport blocks in conditional subsystems
Rationale
Sub ID a:
• The model may not behave as intended when the initial condition is unclear.
3-109
3 Simulink
Verification
Model Advisor check: “Check undefined initial output for conditional subsystems” (Simulink Check)
Last Changed
R2020a
See Also
• “Explore Types of Subsystems”
• “Conditionally Executed Subsystems and Models”
Version History
Introduced in R2020a
3-110
jc_0659: Usage restrictions of signal lines input to Merge blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
3-111
3 Simulink
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of Merge block” (Simulink Check)
Last Changed
R2020a
See Also
• “Explore Types of Subsystems”
• “Conditionally Executed Subsystems Overview”
Version History
Introduced in R2020a
3-112
na_0003: Usage of If blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
For the If block, the if expression and elseif expression shall be used only to define input signals.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-113
3 Simulink
Rationale
Sub ID a:
• Visual comprehension of control conditions is easier when logical operations are described outside
of the If block.
• Describing logical operations outside of the If block allows verification to focus on the logical
operation.
Verification
Model Advisor check: “Check logical expressions in If blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Loops and Conditional Statements”
Version History
Introduced in R2020a
3-114
jc_0656: Usage of Conditional Control blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
To make all actions in the conditions explicit, these block parameters shall be set as follows :
Not Applicable
Example — Correct
3-115
3 Simulink
Example — Incorrect
Rationale
Sub ID a:
• Determining whether there is pointless processing or if something is missing from the design
(such as a missing description) is easier when the processing of exceptions (else, default) is
explicitly set in the model.
Verification
Model Advisor check: “Check default/else case in Switch Case blocks and If blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Conditionally Executed Subsystems Overview”
• “Edit Block Parameters”
• “Select Subsystem Execution”
Version History
Introduced in R2020a
3-116
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Unused action ports shall connect to Terminator block when these conditions are met:
Custom Parameter
Not Applicable
Example — Correct
If block example
3-117
3 Simulink
3-118
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
Example — Incorrect
If block example
3-119
3 Simulink
Sub ID a2
A feedback loop using a Delay block shall be implemented when these conditions are met:
Custom Parameter
Not Applicable
Example — Correct
If block example
3-120
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
3-121
3 Simulink
Example — Incorrect
If block example
3-122
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
3-123
3 Simulink
Rationale
Sub ID a1:
Sub ID a2:
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
Last Changed
R2020a
Version History
Introduced in R2020a
3-124
Operation Blocks
Operation Blocks
3-125
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Logical signals shall not connect to blocks that operate on numerical signals.
Custom Parameter
Example — Incorrect
A logical output is connected directly to the input of blocks that process numerical inputs.
3-126
na_0002: Appropriate usage of basic logical and numerical operations
Sub ID b
Numerical signals shall not connect to blocks that operate on logical signals.
Custom Parameter
Example — Incorrect
3-127
3 Simulink
A block that is used to perform logical operations is being used to perform numerical operations. A
numerical output is connected to the input of blocks that process logical inputs.
A block that is used to perform numerical operations is being used to perform logical operations.
Inputs other than logical values can be provided to the block. However, the Enable port block can
receive only logical signals that have On/Off. The Product block performs logical operations when it
connects the numerical operations result to a block that receives the logical value Enable port.
Rationale
Sub IDs a, b:
• When numerical and logical values are treated the same, the original intention becomes unclear
and the next operation in the model can be incorrectly interpreted, further compounding the error.
Verification
Model Advisor check: “Check fundamental logical and numerical operations” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Basics”
Version History
Introduced in R2020a
3-128
jc_0121: Usage of add and subtraction blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
The icon shape of the add and subtraction Sum block shall be rectangular.
Not Applicable
Example — Correct
The icon shape of the add and subtraction Sum block shall be rectangular.
The second input to the add and subtraction Sum block is a feedback loop, so the icon shape is
round.
3-129
3 Simulink
Example — Incorrect
This is not a feedback loop, but the icon shape of the add and subtractionSum block is round.
Sub ID b
The + mark shall be used for the first input to the add and subtraction Sum block.
For a feedback loop, the first input can be set by using the - mark.
Custom Parameter
Not Applicable
Example — Correct
The + mark is used for the first input to the add and subtraction Sum block.
The second input to the add and subtraction Sum block is a feedback loop, so the - mark is used.
Example — Incorrect
The sign for the first input to the add and subtraction Sum block is the - mark.
Sub ID c
The add and subtraction Sum block shall not have more than two inputs.
3-130
jc_0121: Usage of add and subtraction blocks
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
Sub ID b:
• Readability of the control specification improves when the sign for the first input is consistent.
Sub ID c:
Verification
Model Advisor check: “Check usage of Sum blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-131
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
The * mark shall be used for the first input to a multiplication and division Product block.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-132
jc_0610: Operator order for multiplication and division block
Sub ID b
The multiplication and division Product block shall not have more than two inputs.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
• When checking the block, the input order of the expression and block is reversed, which impairs
readability.
• For floating point numbers, the code is generated according to the operation order in the block --
((1÷1st input)) × 2nd input. However, if division is performed later, then the number of
operations can be reduced.
Sub ID b:
3-133
3 Simulink
Verification
Model Advisor check: “Check operator order of Product blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Multiply and Divide Inputs Using the Product Block”
Version History
Introduced in R2020a
3-134
jc_0611: Input sign for multiplication and division blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When using fixed-point values as the input to the multiplication and division Product block, the sign
of the data type shall be the same for all input signals.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• A utility function is created for each least significant bit (LSB) when fixed-point code is generated.
Unification of data type signs can reduce the number of utility functions.
Verification
Model Advisor check: “Check signs of input signals in product blocks” (Simulink Check)
Last Changed
R2020a
3-135
3 Simulink
See Also
• “Multiply and Divide Inputs Using the Product Block”
Version History
Introduced in R2020a
3-136
jc_0794: Division in Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When using division, implementation of the algorithm shall avoid division by zero.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Deviation from the rule can cause unintended operation and code generation results.
Last Changed
R2021a
See Also
• Multiply “Multiply and Divide Inputs Using the Product Block”
3-137
3 Simulink
Version History
Introduced in R2020a
3-138
jc_0805: Numerical operation block inputs
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2, b, c1/c2, d, e, f1/f2, g, h, i, j
• JMAAB — a1/a2, b, c1/c2, d, e, f1/f2, g, h, i, j
MATLAB Versions
All
Rule
Sub ID a1
When using and Abs block with signed integer types, the input shall not be the most negative value.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-139
3 Simulink
Sub ID a2
Not Applicable
Example — Correct
Example — Incorrect
Sub ID b
Input to the Abs block shall not be unsigned integer types or fixed-point types.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-140
jc_0805: Numerical operation block inputs
Sub ID c1
Not Applicable
Example — Correct
Simulation result
Example — Incorrect
Sub ID c2
Not Applicable
3-141
3 Simulink
Example — Correct
Example — Incorrect
Sub ID d
Input to the Reciprocal Sqrt block shall not be less than zero.
Custom Parameter
Not Applicable
Example — Correct
3-142
jc_0805: Numerical operation block inputs
Example — Incorrect
Sub ID e
When Math Function block parameter Function is set to log or log10, the input to the block shall
not be zero.
Custom Parameter
Not Applicable
Example — Correct
3-143
3 Simulink
Example — Incorrect
Sub ID f1
When Math Function block parameter Function is set to log or log10, the input to the block shall
not be a negative number.
Custom Parameter
Not Applicable
Example — Correct
When the input is less than eps, the value is saturated to eps. Less than eps saturated with eps.
Simulation result
3-144
jc_0805: Numerical operation block inputs
Example — Incorrect
Sub ID f2
When Math Function block parameter Function is set to log or log10, block parameter Output
Signal Type shall be set to complex.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID g
When Math Function block parameter Function is set to mod or rem, the second argument input
shall not be zero.
3-145
3 Simulink
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID h
When Math Function block parameter Function is set to reciprocal, the input to the block shall
not be zero.
Custom Parameter
Not Applicable
Example — Correct
3-146
jc_0805: Numerical operation block inputs
Simulation result: Simulation results is not inf, but since it is close to zero, the change in the output
value is significant.
Example — Incorrect
Sub ID i
When Product block parameter Multiplication is set to Element-wise(.*), the divisor input shall
not be zero.
Note To specify a divisor input, set Product block parameter Number of inputs to */.
Custom Parameter
Not Applicable
3-147
3 Simulink
Example — Correct
Example — Incorrect
Sub ID j
When Product block parameter Multiplication is set to Matrix(*), the divisor input shall not be set
to a singular matrix.
Note To specify a divisor input, set Product block parameter Number of inputs to */.
Custom Parameter
Not Applicable
3-148
jc_0805: Numerical operation block inputs
Example — Correct
Example — Incorrect
Rationale
Sub IDs a1, c1, d, e, f1, g, h, i, j:
• The result of entering an invalid value is implementation dependent. Deviation from the rules can
result in unintended behavior.
Sub ID a2:
• Correct settings prevent unintended behavior that can result from using invalid values.
Sub ID b:
• The block can become optimized out of the generated code, resulting in a block that you cannot
trace to the generated code.
• Correct settings prevent unintended behavior that can result from using negative values.
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
3-149
3 Simulink
Last Changed
R2020a
See Also
• “Specify Block Properties”
• “Control Data Types of Signals”
Version History
Introduced in R2020a
3-150
jc_0622: Usage of Fcn blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When a Fcn block has operators with different priorities, parentheses shall be used to specify the
priority order.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• When operators have different priorities and the computation order is not clearly specified by
using parentheses, readability is impaired and can be misinterpreted. This can result in
unintended behavior.
Verification
Model Advisor check: “Check for parentheses in Fcn block expressions” (Simulink Check)
Last Changed
R2020a
3-151
3 Simulink
See Also
• “Algebraic Loop Concepts”
Version History
Introduced in R2020a
3-152
jc_0621: Usage of Logical Operator blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The icon shape for the Logical Operator block shall be set to rectangular.
Custom Parameter
Not Applicable
Example — Correct
3-153
3 Simulink
Example — Incorrect
Rationale
Sub ID a:
• When describing the same function, using a consistent expression improves readability. Since
"characteristics” shapes are similar, the risk of misinterpretation is greater than with
rectangular shapes.
Verification
Model Advisor check: “Check icon shape of Logical Operator blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-154
jc_0131: Usage of Relational Operator blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When using a Relational Operator block for comparison of signals and constants, the second (bottom)
input shall be used as the constant input.
Custom Parameter
Not Applicable
Example — Correct
3-155
3 Simulink
Example — Incorrect
Rationale
Sub ID a:
• Using constant values and the same comparison method reduces misinterpretation of the model.
Verification
Model Advisor check: “Check usage of Relational Operator blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Relational and Logical Operators” (Embedded Coder)
Version History
Introduced in R2020a
3-156
jc_0800: Comparing floating-point types in Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Equivalence comparison operators (==, ~=) shall not be used on floating-point data types.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-157
3 Simulink
Rationale
Sub ID a:
• Due to the characteristics of the floating-point, since the error is included in the value, the result
of the equivalence comparison operation may be false when it was expected to be true.
Verification
Model Advisor check: “Check comparison of floating point types in Simulink” (Simulink Check)
Last Changed
R2020a
See Also
• “Validate a Floating-Point Embedded Model”
Version History
Introduced in R2020a
3-158
jc_0626: Usage of Lookup Table blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
The Lookup Table Dynamic block parameter Lookup Method shall be set to Interpolation – Use
End Values.
Custom Parameter
Not Applicable
Sub ID b
Custom Parameter
Not Applicable
Rationale
Sub IDs a, b:
• When an unexpected value is entered for the Lookup Table block, the output is determined by
using the extrapolation method and can become an impossible value or cause the Lookup Table
output to overflow.
3-159
3 Simulink
Verification
Model Advisor check: “Check usage of Lookup Tables” (Simulink Check)
Last Changed
R2020a
See Also
• “Methods for Approximating Function Values”
Version History
Introduced in R2020a
3-160
jc_0623: Usage of continuous-time Delay blocks and discrete-time Delay blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
3-161
3 Simulink
Example — Incorrect
Rationale
Sub ID a:
3-162
jc_0623: Usage of continuous-time Delay blocks and discrete-time Delay blocks
Verification
Model Advisor check: “Check usage of Memory and Unit Delay blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Explore Types of Subsystems”
• “Model a Continuous System”
• “Discrete and Continuous Resettable Subsystems”
Version History
Introduced in R2020a
3-163
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
When holding previous past values, Tapped Delay block shall be used to create a vector signal from
all held values.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-164
jc_0624: Usage of Tapped Delay blocks/Delay blocks
Sub ID b
When holding past values, Delay block shall be used to obtain the oldest value only
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-165
3 Simulink
Rationale
Sub ID a:
• Tapped Delay is set with arrays that hold past values, which improves code readability to assist
code efficiency.
Sub ID b:
Verification
Model Advisor check: “Check for cascaded Unit Delay blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Lines”
Version History
Introduced in R2020a
3-166
jc_0627: Usage of Discrete-Time Integrator blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Discrete-Time Integrator block parameters Upper saturation limit and Lower saturation limit
shall be defined.
Custom Parameter
Not Applicable
Example — Correct
3-167
3 Simulink
Example — Incorrect
Note When Discrete-Time Integrator block parameters Upper saturation limit and Lower
saturation limit, are defined with parameter objects such as Simulink.Parameter, the parameter,
Data type should be set to auto. Simulation errors occur when Data type is set to a value other
than auto, single, or double.
Rationale
Sub ID a:
• Avoids block output overflow and prevents other computation blocks that use the output of this
block from producing unexpected results.
Verification
Model Advisor check: “Check usage of Discrete-Time Integrator block” (Simulink Check)
Last Changed
R2024b
See Also
• Simulink.Parameter
3-168
jc_0627: Usage of Discrete-Time Integrator blocks
Version History
Introduced in R2020a
3-169
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Saturation and Saturation Dynamic blocks shall be used to limit physical quantity.
Type conversion shall not be used. Block parameters Upper limit and Lower limit shall not be set.
Custom Parameter
Not Applicable
Example — Correct
3-170
jc_0628: Usage of Saturation blocks
Example — Incorrect
The Saturation Dynamic block is not being used to limit physical quantity. Type conversion is being
used. The upper and lower limits for the data type maximum and minimum values are set.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of the Saturation blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-171
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The Output data type parameter of the output signal of a numerical operation block shall be set to
Inherit:. A Data Type Conversion shall be used when changing the data type of the block output
signal.
Custom Parameter
Not Applicable
Example — Correct
The Output data type parameter of the Divide block is set to Inherit: Inherit via internal
rule.
3-172
jc_0651: Implementing a type conversion
Example — Incorrect
The Output data type parameter of the Divide block is set to int16.
Rationale
Sub ID a:
• Dividing the math operations and type cast can help to clarify the order of execution and data type
for each expression.
Verification
Model Advisor check: “Check Output data type of operation blocks” (Simulink Check)
Last Changed
R2024b
Version History
Introduced in R2020a
3-173
3 Simulink
Other Blocks
3-174
db_0042: Usage of Inport and Outport blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
The Inport block shall be positioned on the left side of the diagram, but can be moved to prevent the
crossing of signals.
Custom Parameter
Not Applicable
Example — Correct
3-175
3 Simulink
Example — Incorrect
Sub ID b
The Outport block shall be positioned on the right side of the diagram, but can be moved to prevent
the crossing of signals.
Custom Parameter
Not Applicable
Example — Correct
3-176
db_0042: Usage of Inport and Outport blocks
Example — Incorrect
Sub ID c
Not Applicable
Example — Correct
Example — Incorrect
3-177
3 Simulink
Rationale
Sub IDs a, b, c:
Verification
Model Advisor check: “Check position of Inport and Outport blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-178
jc_0081: Inport and Outport block icon display
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
For Inport and Outport blocks, parameter Icon Display shall be set to Port number.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-179
3 Simulink
Rationale
Sub ID a:
• Improves readability by displaying the port number of Inport and Outport blocks.
• Allows for easy identification of port numbers that are within a subsystem.
• Prevents misconnections to hierarchized subsystems by displaying the block names and making
the names of signal lines to the Inport and Outport blocks the same as the block names.
Verification
Model Advisor check: “Check display for port blocks” (Simulink Check)
Last Changed
R2020a
See Also
• “Set Block Parameter Values”
• “Signal Basics”
• “Simulink Bus Capabilities”
Version History
Introduced in R2020a
3-180
na_0011: Scope of Goto and From blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Sub ID b
The output signal of Inport block shall not exclusively connect to Goto block.
Custom Parameter
Not Applicable
Example — Correct
The output signal of Inport block connects to something other than Goto block.
3-181
3 Simulink
Example — Incorrect
Sub ID c
The output signal of a From block shall not connect to an Outport block.
Custom Parameter
Not Applicable
Example — Correct
The output signal of a From block does not connect to an Outport block.
Example — Incorrect
3-182
na_0011: Scope of Goto and From blocks
Rationale
Sub ID a:
• When the hierarchies of the Goto block and the corresponding From block are different, the
relationships between the blocks can be difficult to understand.
• Simulation errors can occur when hierarchies of the Goto block and the corresponding From block
are different and a virtual subsystem changes to an Atomic subsystem.
Sub ID b:
• When connecting the output signal of an Inport block to a Goto block, at least one branched signal
connects to blocks other than the Goto block.
Verification
Model Advisor check: “Check scope of From and Goto blocks” (Simulink Check)
Last Changed
R2024b
See Also
• “Programmatically Specify Block Parameters and Properties”
• “Explore Types of Subsystems”
• “Simulink Subsystem Semantics”
Version History
Introduced in R2020a
3-183
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
The smallest scope level shall be used to define the Data Store Memory block.
Custom Parameter
Not Applicable
Sub ID b
Only data required for execution and code generation shall be defined in the Data Store Memory
block.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
Sub ID b:
Verification
Model Advisor check: “Check for usage of Data Store Memory blocks” (Simulink Check)
3-184
jc_0161: Definition of Data Store Memory blocks
Last Changed
R2020a
See Also
• “Data Store Basics”
Version History
Introduced in R2020a
3-185
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The second Switch block input condition shall be a logical type. Switchblock parameter Criteria for
passing first input shall be set to u2~=0.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• It is easier to understand specifications when the configuration is applied by using Simulink blocks
rather than by writing operation expressions in blocks.
Verification
Model Advisor check: “Check usage of Switch blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-186
jc_0650: Block input/output data type with switching function
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
For blocks with switching functions (Switch, Multiport Switch, and Index Vector), the same data type
shall be used for data ports and output ports.
Custom Parameter
Not Applicable
Example — Correct
The data type for the data port and output port is the same.
3-187
3 Simulink
Example — Incorrect
The data port and output port have different data types.
3-188
jc_0650: Block input/output data type with switching function
Rationale
Sub ID a:
Verification
Model Advisor check: “Check input and output datatype for Switch blocks” (Simulink Check)
Last Changed
R2020a
Version History
Introduced in R2020a
3-189
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Multiport Switch block parameter Number of data ports shall be two or more.
Custom Parameter
Not Applicable
Example — Correct
3-190
jc_0630: Usage of Multiport Switch blocks
Example — Incorrect
Sub ID b
The data type of the input signal to the control port of Multiport Switch shall be:
Not Applicable
Example — Correct
Example — Incorrect
Sub ID c
When Multiport Switch block parameter Data port order is set to Specify indices, these block
parameters shall be set as follows:
Not Applicable
3-191
3 Simulink
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
• Unintended output can occur when there is only one data port because the block changes to
extract scalars from vectors.
Sub ID b:
• The control port is an input range that expects an integer value of zero or greater. When a signed
or non-integer signal is connected to the control port, it can appear as a misconnection.
3-192
jc_0630: Usage of Multiport Switch blocks
• There is a possibility of data ports being unintentionally selected when negative or non-integer
values are input.
Sub ID c:
• When block parameter Data port order is set to Specify indices, a value that inputs to the
Multiport Switch block, other than the index specified for the control port, is treated the same as
the last value of the specified index. As a result, an unintended data port can be selected.
Verification
Model Advisor check: “Check settings for data ports in Multiport Switch blocks” (Simulink Check)
Last Changed
R2024b
Version History
Introduced in R2020a
3-193
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
The number of inputs/outputs for a Variant Subsystem block and its child structured subsystem or
model reference shall be the same.
Custom Parameter
Not Applicable
Example — Correct
3-194
na_0020: Number of inputs to variant subsystems
Example — Incorrect
Sub ID b
The number of inputs/outputs for a Variant Model block shall be the same as its referenced model.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
The number of inputs to the referenced model is different than the inputs to the Variant Model block.
3-195
3 Simulink
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check for missing ports in Variant Subsystems” (Simulink Check)
Last Changed
R2024b
See Also
• “Explore Types of Subsystems”
• “Model Reference Basics”
• “Create a Simple Variant Model”
Version History
Introduced in R2020a
3-196
na_0036: Default variant
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Variant subsystems shall be configured so that one subsystem is always selected. This is achieved by
using one of these methods:
Custom Parameter
Not Applicable
Example — Correct
3-197
3 Simulink
Example — Incorrect
Sub ID b
Model variant conditions shall be set so all values that can be applied to conditional variable signals
are configured so one subsystem is always selected. For example, a condition is prepared for the
variable signal value being true, as well as false.
Custom Parameter
Not Applicable
Example — Correct
The condition is set so that all values for the conditional variable are covered.
Example — Incorrect
3-198
na_0036: Default variant
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check use of default variants” (Simulink Check)
Last Changed
R2020a
See Also
• “Implement Variations in Separate Hierarchy Using Variant Subsystems”
• “Propagate Variant Conditions to Define Variant Regions in Virtual and Nonvirtual Subsystems”
Version History
Introduced in R2020a
3-199
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Variant conditions shall be used to prohibit compound conditions that are formed from multiple
variables.
Exception
Conditional expressions that are formed from multiple variables can be used when using default
variants.
Custom Parameter
Not Applicable
Example — Correct
The variant condition is set by a single condition that is formed from multiple variables.
The usage of enumerated type variables is recommended in a condition equation. This example uses
numerical values to improve readability.
3-200
na_0037: Use of single variable for variant condition
Example — Incorrect
The variant condition is set by a compound condition that is formed from multiple variables.
Rationale
Sub ID a:
• Complicates the conditions, which makes it difficult to determine which subsystem will become
active. This can result in conditions being omitted.
• When conditions are omitted, there is a risk that there may not be an active subsystem.
Verification
Model Advisor check: “Check use of single variable variant conditionals” (Simulink Check)
Last Changed
R2020a
See Also
• “What Are Variants and When to Use Them”
• “Introduction to Variant Controls”
Version History
Introduced in R2020a
3-201
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Underscores shall not be used at the end of bus object names, enumeration class names, or
enumeration member names.
Custom Parameter
Not Applicable
Example — Incorrect
3-202
jc_0900: Usable characters for data type definition
Sub ID b
Consecutive underscores shall not be used in bus object names, enumeration class names, or
enumeration member names.
Custom Parameter
Not Applicable
Example — Incorrect
Sub ID c
Bus object names, enumeration class names and enumeration member names shall not be the same
as reserved MATLAB words.
Custom Parameter
Not Applicable
Example — Incorrect
A reserved MATLAB word that exactly matches the enumeration class name is used.
3-203
3 Simulink
A reserved MATLAB word that exactly matches the enumeration member name is used.
Rationale
Sub ID a:
• Deviation reduces readability. Since underscores are commonly used as word separators, it may
look like a typographical error.
Sub ID b:
Sub ID c:
• Deviation reduces readability. Deviating from common practices may lead to unexpected
problems.
Verification
Model Advisor check: “Check bus and enumeration data type names” (Simulink Check)
Last Changed
R2024b
See Also
“Specify Bus Properties with Bus Objects”
Version History
Introduced in R2024b
3-204
jc_0901: Length restriction for Bus and Enumeration data type names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The number of characters in a bus object name, enumeration class name, or enumeration member
name shall be less than or equal to the configured limit. The default is 63.
Custom Parameter
When the maximum number of characters is set to 31. The bus object, enumeration class, and
enumeration member names are longer than 31 characters.
3-205
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of bus and enumeration data type names” (Simulink Check)
Last Changed
R2024b
See Also
“Specify Bus Properties with Bus Objects”
Version History
Introduced in R2024b
3-206
jc_0902: Arrowhead size of transition lines
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The arrowhead {size} of transition lines shall be set to the value defined in the project.
Custom Parameter
Example — Correct
Example — Incorrect
3-207
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check arrowhead size of transition lines” (Simulink Check)
Last Changed
R2024b
See Also
“Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2024b
3-208
jc_0903: Prohibition of overlapping or crossing of blocks and signal lines
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b1/b2
• JMAAB — a, b1/b2
MATLAB Versions
All
Rule
Sub ID a
Blocks, block names, block annotations, annotations, and signal labels shall not overlap.
Exception
When modeling within an annotation frame by treating the frame as a subsystem boundary, only the
lines of the annotation frame, not the entire frame, are subject to this rule.
Custom Parameter
Not Applicable
Example — Correct
3-209
3 Simulink
Example — Incorrect
Sub ID b1
• Signal lines shall not overlap with blocks, block names, block annotations, annotations, signal
lines, or signal labels.
• Signal lines shall not intersect with other signal lines.
Custom Parameter
Not Applicable
Exception
Intersection of annotation frames and signal lines when modeling within an annotation frame by
considering the frame as a subsystem boundary.
Example — Incorrect
Signal lines overlap with blocks and block names, and also and intersect with other signal lines.
Sub ID b2
Custom Parameter
Not Applicable
3-210
jc_0903: Prohibition of overlapping or crossing of blocks and signal lines
Exception
Intersection of annotation frames and signal lines when modeling within an annotation frame by
considering the frame as a subsystem boundary.
Example — Correct
Example — Incorrect
Rationale
Sub IDs a, b1, b2:
Verification
Model Advisor check: “Check for prohibited overlapping or intersecting blocks and signal lines”
(Simulink Check)
3-211
3 Simulink
Last Changed
R2024b
See Also
“Signal Basics”
Version History
Introduced in R2024b
3-212
jc_0904: Prohibition of overlap/intersection of states and transition lines
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
States, graphical functions, Simulink functions, MATLAB functions, truth tables, boxes, junctions,
annotations, or text labels shall not overlap.
Custom Parameter
Not Applicable
Exceptions
• Overlapping of parent and child in hierarchical modeling, provided that the child is contained
within the parent's frame.
• States and their labels must fit within the state frame. Likewise for graphical functions, Simulink
functions, MATLAB functions, truth tables, and boxes.
Supplement
3-213
3 Simulink
Example — Incorrect
Sub ID b
Transition lines shall not overlap or intersect with states, graphical functions, Simulink functions,
MATLAB functions, truth tables, boxes, junctions, annotations, text labels, or other transition lines.
Custom Parameter
Not Applicable
Exceptions
• Overlapping of parent and child in hierarchical modeling, provided that the child is contained
within the parent's frame.
3-214
jc_0904: Prohibition of overlap/intersection of states and transition lines
Example — Correct
Since this is an intersection for crossing state hierarchies, it does not violate the rules.
Example — Incorrect
Rationale
Sub IDs a, b:
3-215
3 Simulink
Verification
Model Advisor check: “Check for prohibited overlapping of states and transition lines in Stateflow
charts” (Simulink Check)
Last Changed
R2024b
See Also
• “Signal Basics”
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2024b
3-216
jc_0905: Usable characters for data names in Functions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Data names defined within MATLAB functions shall not use underscores at the end.
Custom Parameter
Not Applicable
Sub ID b
Consecutive underscores shall not be used in data names defined within MATLAB functions.
Custom Parameter
Not Applicable
Sub ID c
Data names defined within a MATLAB functions shall not be the same as reserved MATLABwords.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
3-217
3 Simulink
• Deviation reduces readability. Since underscores are commonly used as word separators, it may
look like a typographical error.
Sub ID b:
Sub ID c:
Verification
Model Advisor check: “Check data names in MATLAB functions” (Simulink Check)
Last Changed
R2024b
See Also
“Model Reference Data Storage”
Version History
Introduced in R2024b
3-218
jc_0906: Length restriction of data names in MATLAB Functions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The number of characters for data names defined within a MATLAB function shall be less than or
equal to configured limit. The default is 63.
Custom Parameter
The maximum number of characters for data names in MATLAB function is 63.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check the length of data names in MATLAB functions” (Simulink Check)
Last Changed
R2024b
3-219
3 Simulink
See Also
“Reserved Keywords” (Embedded Coder)
Version History
Introduced in R2024b
3-220
jc_0907: Size of a Junction
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The size of junctions shall be set to the value defined in the project.
Custom Parameter
Size of junctions
Example — Correct
Example — Incorrect
3-221
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check size of junctions” (Simulink Check)
Last Changed
R2024b
See Also
“Represent Multiple Paths by Using Connective Junctions” (Stateflow)
Version History
Introduced in R2024b
3-222
mp_0007: How to describe executable statements
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
if foo > 0
bar = 10;
end
Example — Incorrect
Sub ID b
foo = 1 + 2;
Example — Incorrect
foo = 1 + 2
Rationale
Sub IDs a:
3-223
3 Simulink
Sub ID b:
Verification
Model Advisor check: “Check description of execution statements” (Simulink Check)
Last Changed
R2024b
Version History
Introduced in R2024b
3-224
mp_0008: Format of parentheses
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Single-byte spaces shall not be inserted between function/variable names and left parentheses.
Example — Correct
fcnc(arg)
foo(bar)
Example — Incorrect
fcnc (arg)
foo (bar)
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for spaces between function or variable names and left parenthesis
symbol” (Simulink Check)
Last Changed
R2024b
3-225
3 Simulink
Version History
Introduced in R2024b
3-226
mp_0010: Precedence of Operators in Arithmetic Expressions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When an expression contains operators with different precedence levels, parentheses shall be used to
clarify the order of operations.
Example — Correct
When the operators have the same precedence, parentheses are unnecessary.
Example — Incorrect
Rationale
Sub ID a:
3-227
3 Simulink
Verification
Model Advisor check: “Check for operator precedence” (Simulink Check)
Last Changed
R2024b
See Also
“Operator Precedence”
Version History
Introduced in R2024b
3-228
mp_0011: Method of inserting a single-width space
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
At least one space shall be inserted before and after operators and after commas.
Single-byte spaces shall not be inserted between unary operators and operands.
Example — Correct
x = -baz;
Example — Incorrect
foo=bar+baz;
strcmp(qux, 'AEIOU')
x = - baz;
Rationale
Sub ID a:
• The proper use of spaces around operators and commas can improve readability.
Verification
Model Advisor check: “Check spaces in expressions” (Simulink Check)
3-229
3 Simulink
Last Changed
R2024b
Version History
Introduced in R2024b
3-230
mp_0022: Format of Conditional Expressions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c1/c2
• JMAAB — a, b, c1/c2
MATLAB Versions
All
Rule
Sub ID a
Conditional expressions shall be written as expressions that evaluate to a single logical value (true or
false).
Example — Correct
% foo
・・・ a non-logical variable
if (foo ~= 0)
Example — Incorrect
% foo
・・・ a non-logical variable
if foo
Sub ID b
The number of binary operators per line in a conditional expression shall be defined.
Example — Correct
% If up to 3 is allowed
if (foo1 && foo2) ...
|| (foo3 && foo4 && foo5)
Example — Incorrect
% If up to 3 is allowed
if (foo1 && foo2) || (foo3 && foo4 && foo5)
3-231
3 Simulink
Custom Parameter
Sub ID c1
When dividing a conditional expression into multiple lines, line breaks shall be inserted immediately
after a logical operator, and the subsequent lines shall be indented.
Example — Correct
if foo1 || ...
foo2 || ...
foo3
end
Example — Incorrect
if foo1 ...
|| foo2 ...
|| foo3
end
Sub ID c2
When dividing a conditional expression into multiple lines, line breaks shall be inserted immediately
before a logical operator, and the subsequent lines shall have aligned indentation.
Example — Correct
if foo1 ...
|| foo2 ...
|| foo3
end
Example — Incorrect
if foo1 || ...
foo2 || ...
foo3
end
Rationale
Sub ID a:
Sub ID b:
• Limiting the number of operators makes it easy to understand the relationships between each
condition.
Sub ID b:
• Limiting the number of operators makes it easy to understand the relationships between each
condition.
3-232
mp_0022: Format of Conditional Expressions
Verification
Model Advisor check: “Check description of conditional expressions” (Simulink Check)
Last Changed
R2024b
See Also
“Operator Precedence”
Version History
Introduced in R2024b
3-233
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1, a2
• JMAAB — a1, a2
MATLAB Versions
All
Rule
Sub ID a1
When you are using relational operators with variables and constants, the constants shall be placed
on the right-hand side.
Example — Correct
foo = 10;
if bar >= foo
ret1 = 1;
end
Example — Incorrect
foo = 10;
if foo <= bar
ret1 = 1;
end
Sub ID a2
When you are using relational operators with variables and constants, the constants shall be placed
on the left-hand side.
Example — Correct
foo = 10;
if foo <= bar
ret1 = 1;
end
3-234
mp_0023: Format of relational operations using constants
Example — Incorrect
foo = 10;
if bar >= foo
ret1 = 1;
end
Rationale
Sub IDs a1, a2:
Verification
Model Advisor check: “Check relational operators usage” (Simulink Check)
Last Changed
R2024b
Version History
Introduced in R2024b
3-235
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The descriptive items can include an overview, processing details, input and output arguments,
management information and other relevant information. The combination of descriptive items shall
be adjusted for main functions and sub-functions as needed.
Example — Correct
foo = 3;
ret = arg1 + foo;
end
Custom Parameter
3-236
mp_0032: Function header information
Rationale
Sub ID a:
Verification
Model Advisor check: “Check function headers” (Simulink Check)
Last Changed
R2024b
See Also
• na_0025: MATLAB Function header
Version History
Introduced in R2024b
3-237
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Example — Correct
• Lines of the range that can be collapsed at the function line in the editor are counted.
• The help text just below the function line should be collapsed and counted.
• The number of lines in the libinfo function is 88 in the following example.
3-238
mp_0034: Number of lines in a function
Custom Parameter
• Number of lines
Rationale
Sub ID a:
• When a function has too many lines, it can be difficult to understand and maintain the function.
Separating it by each feature deepens understanding of the functions and can limit the range
affected by changes.
Verification
Model Advisor check: “Check number of lines of functions” (Simulink Check)
Last Changed
R2024b
See Also
• “Integrate MATLAB Functions in a Stateflow Charts” (Stateflow)
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
Version History
Introduced in R2024b
3-239
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
ret1 = func1(arg1);
ret2 = func2(arg2);
ret = ret1 + ret2;
Example — Incorrect
Rationale
Sub ID a:
• Although it is not syntactically incorrect to use the return values of functions directly, the results
may vary depending on the order of the function evaluation.
Readability improves where the return values of functions are assigned to variables before use,
rather than where the return values are used directly in operations.
Verification
Model Advisor check: “Check for utilization of the return value of functions” (Simulink Check)
3-240
mp_0040: Using the return value of a function
Last Changed
R2024b
See Also
• jc_0511: Return values from a graphical function
Version History
Introduced in R2024b
3-241
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Array indices shall not be used to calculate array numbers. However, arithmetic operations with end
and the colon operator are exceptions.
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
• Calculating values before using them as indices to access array elements reduces readability.
Verification
Model Advisor check: “Check array indices” (Simulink Check)
3-242
mp_0046: Usage of expressions in array indices
Last Changed
R2024b
Version History
Introduced in R2024b
3-243
3 Simulink
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Example — Incorrect
foo;
bar == 1;
Rationale
Sub ID a:
• Non-empty statements should be written to change data values or alter control flow, impacting the
execution results in some way. Statements that do not meet these criteria are unnecessary and
may not reflect the designer's intentions.
Verification
Model Advisor check: “Check for usage of nonempty statements” (Simulink Check)
3-244
mp_0047: Conditions that a nonempty statement must satisfy
Last Changed
R2024b
Version History
Introduced in R2024b
3-245
4
Stateflow
4-2
db_0123: Stateflow port names
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
The name of a Stateflow input/output shall be the same as the corresponding signal.
Exception
Not Applicable
Rationale
Sub ID a:
• Improves readability.
• Code generation may not be possible.
Verification
Model Advisor check: “Check for names of Stateflow ports and associated signals” (Simulink Check)
Last Changed
R2020a
4-3
4 Stateflow
See Also
• “Set Data Properties” (Stateflow)
• “Reusable Components in Charts” (Stateflow)
Version History
Introduced in R2020a
4-4
db_0125: Stateflow local data
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d
• JMAAB — a, b, c, d
MATLAB Versions
All
Rule
Sub ID a
Data objects shall not be defined with Scope set to Local at the machine level.
Custom Parameter
Not Applicable
4-5
4 Stateflow
Example — Correct
Example — Incorrect
4-6
db_0125: Stateflow local data
Sub ID b
Data objects shall not be defined with Scope set to Constant at the machine level.
Custom Parameter
Not Applicable
4-7
4 Stateflow
Example — Correct
Example — Incorrect
4-8
db_0125: Stateflow local data
Sub ID c
Data objects shall not be defined with Scope set to Parameter at the machine level.
Custom Parameter
Not Applicable
4-9
4 Stateflow
Example — Correct
Example — Incorrect
4-10
db_0125: Stateflow local data
Sub ID d
A Stateflow block with parent-child relationships shall not include stateflow data with the same name.
Custom Parameter
Not Applicable
Example — Correct
4-11
4 Stateflow
Example — Incorrect
A Stateflow block with parent-child relationships has local data with the same name.
Rationale
Sub ID a:
• When local data is defined at the machine level, it is shared with all blocks in the model. The data
will not behave like a local variable and can be influenced by any operation.
• Adherence to the rules prevent the definition from disappearing when copying a Stateflow block to
another model.
Sub IDs b, c:
• Adherence to the rules prevent the definition from disappearing when copying a Stateflow block to
another model.
Sub ID d:
4-12
db_0125: Stateflow local data
• When a Stateflow block with parent-child relationships includes stateflow data with the same
name, readability decreases due to lack of clarity with regard to the influence of the stateflow
data.
Verification
Model Advisor check: “Check definition of Stateflow data” (Simulink Check)
Last Changed
R2024b
See Also
• “Stateflow Data Properties” (Stateflow)
• “Use the Model Explorer with Stateflow Objects” (Stateflow)
• “Use State Hierarchy to Design Multilevel State Complexity” (Stateflow)
Version History
Introduced in R2020a
4-13
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Stateflow events shall be defined by the smallest scope level in the Stateflow block being used.
Custom Parameter
Not Applicable
4-14
db_0126: Defining Stateflow events
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check definition of Stateflow events” (Simulink Check)
4-15
4 Stateflow
Last Changed
R2020a
See Also
• “Synchronize Model Components by Broadcasting Events” (Stateflow)
• “Use the Model Explorer with Stateflow Objects” (Stateflow)
Version History
Introduced in R2020a
4-16
jc_0701: Usable number for first index
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
When Stateflow Chart property Action language is set to C, Stateflow data property First Index
shall be set to 0.
Custom Parameter
Not Applicable
4-17
4 Stateflow
Example — Correct
Example — Incorrect
4-18
jc_0701: Usable number for first index
Sub ID a2
When Stateflow Chart property Action language is set to C, Stateflow data property First Index
shall be set to 1.
Custom Parameter
Not Applicable
4-19
4 Stateflow
Example — Correct
Example — Incorrect
4-20
jc_0701: Usable number for first index
Rationale
Sub ID a1:
Sub ID a2:
• Logic becomes easier to understand when First Index is uniform. However, C language is 0-
based, which decreases the readability of the code as the index calculation process is 1-based.
This is reflected in the generated code.
Verification
Model Advisor check: “Check usable number for first index” (Simulink Check)
4-21
4 Stateflow
Last Changed
R2020a
See Also
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
• “Set Data Properties” (Stateflow)
Version History
Introduced in R2020a
4-22
jc_0712: Execution timing for default transition path
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Stateflow Chart property Execute (enter) chart at initialization shall not be selected.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Using the same settings for each Stateflow Chart prevents the model from being misinterpreted.
• Use caution when referencing an input signal using the default transition line when property
Execute (enter) chart at initialization is selected.
Verification
Model Advisor check: “Check execution timing for default transition path” (Simulink Check)
Last Changed
R2020a
4-23
4 Stateflow
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
Version History
Introduced in R2020a
4-24
jc_0722: Local data definition in parallel states
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Local variables that are completed in one state shall be defined in that state.
Custom Parameter
Not Applicable
Example — Correct
4-25
4 Stateflow
Example — Incorrect
4-26
jc_0722: Local data definition in parallel states
Rationale
Sub ID a:
• Readability and maintainability can be improved by explicitly limiting the valid range of the
variables, thereby avoiding unintended references and changes.
Verification
Model Advisor check: “Check scope of data in parallel states” (Simulink Check)
Last Changed
R2020a
4-27
4 Stateflow
See Also
• “Represent Operating Modes by Using States” (Stateflow)
• “Parallel and Exclusive States” (Stateflow)
Version History
Introduced in R2020a
4-28
Stateflow Diagram
Stateflow Diagram
4-29
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-30
jc_0797: Unconnected transitions / states / connective junctions
Sub ID b
Stateflow Chart shall not have unconnected exclusive (OR) states and connective junctions without a
transition source.
Custom Parameter
Not Applicable
Example — Correct
Does not have unconnected exclusive (OR) states or connective junctions without a transition source.
Example — Incorrect
There are unconnected exclusive (OR) states and connective junctions without a transition source.
Rationale
Sub IDs a, b:
4-31
4 Stateflow
Verification
Model Advisor check: “Check for unconnected objects in Stateflow Charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Combine Transitions and Junctions to Create Branching Paths” (Stateflow)
• “Define Exclusive and Parallel Modes by Using State Decomposition” (Stateflow)
• “Transition Between Exclusive States” (Stateflow)
• “Represent Multiple Paths by Using Connective Junctions” (Stateflow)
Version History
Introduced in R2020a
4-32
db_0137: States in state machines
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When the Decomposition for the Chart block or State is set to OR (Exclusive), there shall be at
least two states in the hierarchy.
Custom Parameter
Not Applicable
Example — Incorrect
The hierarchy contains only one state when the Decomposition option is set to OR (Exclusive)
4-33
4 Stateflow
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for state in state machines” (Simulink Check)
Last Changed
R2020a
See Also
• “Represent Operating Modes by Using States” (Stateflow)
• “Define Exclusive and Parallel Modes by Using State Decomposition” (Stateflow)
Version History
Introduced in R2020a
4-34
jc_0721: Usage of parallel states
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
4-35
4 Stateflow
Example — Correct
Example — Incorrect
4-36
jc_0721: Usage of parallel states
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of parallel states” (Simulink Check)
Last Changed
R2020a
4-37
4 Stateflow
See Also
• “Represent Operating Modes by Using States” (Stateflow)
• “Parallel and Exclusive States” (Stateflow)
• “Use State Hierarchy to Design Multilevel State Complexity” (Stateflow)
Version History
Introduced in R2020a
4-38
db_0129: Stateflow transition appearance
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-39
4 Stateflow
Example — Incorrect
Sub ID b
Not Applicable
Example — Correct
Example — Incorrect
4-40
db_0129: Stateflow transition appearance
Rationale
Sub ID a:
Sub ID b:
• Transitions can be difficult to understand when unnecessary connective junctions are used.
Verification
Model Advisor check: “Check for Stateflow transition appearance” (Simulink Check)
Last Changed
R2024b
See Also
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-41
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e, f, g
• JMAAB — a, b, c, d, e, f, g
MATLAB Versions
All
Rule
Sub ID a
When Decomposition of a Stateflow Chart is Exclusive (OR), the default transition shall connect
at the top of the Chart block.
When Decomposition of the state is Exclusive (OR), the default transition shall connect
immediately beneath the state.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-42
jc_0531: Default transition
Sub ID b
When Decomposition is set to “Parallel (AND)”, the default transition line shall not be connected.
Custom Parameter
Not Applicable
Example — Correct
Decomposition of the parent object for states AA and AB is set to Parallel (AND), which makes
states AA and AB parallel states. The default transition line is not connected for these parallel states.
Example — Incorrect
Sub ID c
Not Applicable
4-43
4 Stateflow
Example — Correct
Example — Incorrect
4-44
jc_0531: Default transition
Sub ID d
Default transitions shall be connected directly and positioned vertically to the upper part of the state
or connective junction.
Custom Parameter
Not Applicable
Example — Correct
The default transition is connected vertically to the upper part of the state.
Example — Incorrect
The default transition of state A is not connected vertically to the upper part of the state.
4-45
4 Stateflow
Sub ID e
The destination state or destination connective junction for the default transition shall be positioned
to the top left in the same level.
Custom Parameter
Not Applicable
Example — Correct
The default transition is positioned to the top left in the same level.
Example — Incorrect
The default transition of state AB is not positioned to the top left in the same level.
4-46
jc_0531: Default transition
Sub ID f
Default transitions shall not extend beyond the boundaries of the state.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-47
4 Stateflow
Sub ID g
Configuration parameter No unconditional default transitions shall be set to Error to ensure that
in the transition path for the default transition, the path with the lowest priority is an unconditional
transition.
Custom Parameter
Not Applicable
Example — Correct
The path with the lowest priority in the transition path for the default transition is an unconditional
transition.
Example — Incorrect
The path with the lowest priority in the transition path for the default transition is not an
unconditional transition.
4-48
jc_0531: Default transition
Rationale
Sub ID a:
• Simulation errors can occur when a state chart does not include default transition lines.
• When default transitions are included in a flow chart, it is impossible to determine whether this is
intentional or through failure to insert them.
Sub ID b:
Sub ID c:
• The state may not function as intended and produce a warning when multiple default transitions
are included in the same level.
Sub ID d:
• Readability decreases when there are curves or variations in the angle or position of default
transitions.
Sub ID e:
• Readability decreases when there are variations in the position of the transition destination state
or transition destination connective junction for the default transition.
Sub ID f
• Readability decreases when a default transition extends beyond the boundary of a state and
intersects with state boundaries and expressions.
Sub ID g:
• When there is not an unconditional transition in the transition path of the default transition, the
transition destination disappears if all conditions of the transition path are not met. This can result
in unintended behavior.
4-49
4 Stateflow
Verification
Model Advisor check: “Check default transition placement in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Define Exclusive and Parallel Modes by Using State Decomposition” (Stateflow)
• “Transition Between Operating Modes” (Stateflow)
• “How Stateflow Objects Interact During Execution” (Stateflow)
Version History
Introduced in R2020a
4-50
jc_0723: Prohibited direct transition from external state to child state
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Transitions from one state directly to an external child state shall be prohibited.
Custom Parameter
Not Applicable
Example — Correct
4-51
4 Stateflow
Example — Incorrect
4-52
jc_0723: Prohibited direct transition from external state to child state
Direct transition from an external child state to a child state in a different state.
Rationale
Sub ID a:
• Direct transitions between child states can complicate the states and decrease readability.
Verification
Model Advisor check: “Check usage of transitions to external states” (Simulink Check)
4-53
4 Stateflow
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-54
jc_0751: Backtracking prevention in state transition
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
4-55
4 Stateflow
Rationale
Sub ID a:
• Deviation from the rule can cause backtracking, which results in unintended behavior.
Verification
Model Advisor check: “Check for unexpected backtracking in state transitions” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Combine Transitions and Junctions to Create Branching Paths” (Stateflow)
• “Evaluate Transitions” (Stateflow)
Version History
Introduced in R2020a
4-56
jc_0760: Starting point of internal transition
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Internal transition lines shall start from the left edge of the state.
Custom Parameter
Not Applicable
Example — Correct
The inner transition line begins at the left edge of the state.
4-57
4 Stateflow
Example — Incorrect
The inner transition line does not begin at the left edge of the state.
4-58
jc_0760: Starting point of internal transition
Rationale
Sub ID a:
Verification
Model Advisor check: “Check starting point of internal transition in Stateflow” (Simulink Check)
Last Changed
R2020a
See Also
• “Control Chart Execution by Using Inner Transitions” (Stateflow)
Version History
Introduced in R2020a
4-59
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
4-60
jc_0763: Usage of multiple internal transitions
Example — Incorrect
4-61
4 Stateflow
Sub ID a2
When multiple internal transitions are used in a single state, they shall be listed from top to bottom in
the order of execution.
Custom Parameter
Not Applicable
Example — Correct
4-62
jc_0763: Usage of multiple internal transitions
Example — Incorrect
Rationale
Sub ID a1:
• The number of transition conditions is unclear when multiple internal transitions are used. By
limiting the use of internal transitions to a single use, transitions are clearer and readability
improves.
Sub ID a2:
• Using multiple internal transitions can prevent transition lines from crossing and simplifies state
transitions.
• Arranging internal transitions in execution order improves readability.
Verification
Model Advisor check: “Check usage of internal transitions in Stateflow states” (Simulink Check)
Last Changed
R2020a
See Also
• “Overview of Stateflow Objects” (Stateflow)
• “Transition Between Operating Modes” (Stateflow)
• “Types of Chart Execution” (Stateflow)
Version History
Introduced in R2020a
4-63
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
A state shall not include state actions (en, du, or ex) and flow charts.
Custom Parameter
Not Applicable
Example — Correct
4-64
jc_0762: Prohibition of state action and flow chart combination
Example — Incorrect
The state includes state actions en and du and also a flow chart.
4-65
4 Stateflow
Rationale
Sub ID a:
Verification
Model Advisor check: “Check prohibited combination of state action and flow chart” (Simulink Check)
Last Changed
R2020a
See Also
• “Create Flow Charts in Stateflow” (Stateflow)
• “Represent Operating Modes by Using States” (Stateflow)
4-66
jc_0762: Prohibition of state action and flow chart combination
Version History
Introduced in R2020a
4-67
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
4-68
db_0132: Transitions in flow charts
Sub ID b
In a flow chart, the condition shall be positioned on a horizontal transition line and the condition
action shall be positioned on a vertical transition line.
Exception
Not Applicable
Example — Correct
The condition is positioned on a horizontal transition line and the condition action is on a vertical
transition line.
Example — Incorrect
The condition is positioned on a vertical transition line and the condition action is on a horizontal
transition line.
Rationale
Sub ID a:
4-69
4 Stateflow
Sub ID b:
Verification
Model Advisor check: “Check transitions in Stateflow Flow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-70
jc_0773: Unconditional transition of a flow chart
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
When a transition line with a transition condition originates from a connective junction, the
unconditional transition line shall also begin from that junction.
Custom Parameter
Not Applicable
4-71
4 Stateflow
Example — Correct
Example — Incorrect
4-72
jc_0773: Unconditional transition of a flow chart
Sub ID b
The execution order for unconditional transitions shall be set to the last value.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
The execution order for unconditional transitions is not the last value.
4-73
4 Stateflow
Rationale
Sub ID a:
• Prevents unintended behavior that results from backtracking. Setting an unconditional transition
explicitly defines the behavior for when the condition is not met.
Sub ID b:
• Setting the unconditional transition to take precedence can prevent unintended behavior.
Verification
Model Advisor check: “Check usage of unconditional transitions in flow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
4-74
jc_0773: Unconditional transition of a flow chart
Version History
Introduced in R2020a
4-75
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-76
jc_0775: Terminating junctions in flow charts
Sub ID a2
One terminating junction with a single unconditional transition as the input shall be used.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-77
4 Stateflow
Rationale
Sub IDs a1, a2
Verification
Model Advisor check: “Check terminal junctions in Stateflow” (Simulink Check)
Last Changed
R2020a
See Also
• “Evaluate Transitions” (Stateflow)
• “Represent Multiple Paths by Using Connective Junctions” (Stateflow)
Version History
Introduced in R2020a
4-78
jc_0738: Usage of Stateflow comments
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
When Chart parameter Action Language is set to C, /*...*/ comment nesting shall not be used.
Custom Parameter
Not Applicable
Example — Correct
4-79
4 Stateflow
Example — Incorrect
Sub ID b
When Chart parameter Action Language is set to C, new line characters for comments /* */ shall
not be used in the middle of a single comment.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
4-80
jc_0738: Usage of Stateflow comments
Sub ID b:
• A line break in the middle of a comment makes it difficult to determine whether the part being
edited is in the comment. There is also a possibility that the comment is nested.
• When Chart parameter Action Language is set to MATLAB, comments must use %.
Verification
Model Advisor check: “Check usage of Stateflow comments” (Simulink Check)
Last Changed
R2020a
See Also
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
• “Modify the Action Language for a Chart” (Stateflow)
Version History
Introduced in R2020a
4-81
4 Stateflow
4-82
jc_0790: Action language of Chart block
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-83
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
• Using a consistent action language improves readability because there is not a difference in
syntax.
• Easier to maintain consistency between the model and the generated code when using C as the
action language as compared to MATLAB.
• Easier to understand the model for users who are familiar with the C programming language.
Verification
Model Advisor check: “Check Stateflow chart action language” (Simulink Check)
Last Changed
R2020a
See Also
• “Modify the Action Language for a Chart” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Version History
Introduced in R2020a
4-84
jc_0702: Use of named Stateflow parameters and constants
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
• Initial value is 0
• Increment, decrement 1
Custom Parameter
Not Applicable
Example — Correct
4-85
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
• Only the modeler will understand the purpose of the value when numeric literals are used to write
constants, which decreases readability.
• Constants that are intended for calibration are generated in the code using numeric literals.
Verification
Model Advisor check: “Check usage of numeric literals in Stateflow” (Simulink Check)
Last Changed
R2020a
See Also
• “Guidelines for Naming Stateflow Objects” (Stateflow)
4-86
jc_0702: Use of named Stateflow parameters and constants
Version History
Introduced in R2020a
4-87
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
4-88
jm_0011: Pointers in Stateflow
Example — Correct
Example — Incorrect
4-89
4 Stateflow
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for pointers in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Pointer and Address Operations” (Stateflow)
4-90
jm_0011: Pointers in Stateflow
Version History
Introduced in R2020a
4-91
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
A variable shall not have multiple meanings (usages) in a single Stateflow Chart.
Custom Parameter
Not Applicable
Example — Correct
4-92
jc_0491: Reuse of Stateflow data
Example — Incorrect
4-93
4 Stateflow
Rationale
Sub ID a:
• Variables can be misinterpreted when the variable name is different than the meaning of the
numerical value that is assigned to the variable.
Verification
Model Advisor check: Adherence to this modeling guideline cannot be verified by using a Model
Advisor check.
4-94
jc_0491: Reuse of Stateflow data
Last Changed
R2020a
See Also
• “Construct and Run a Stateflow Chart” (Stateflow)
Version History
Introduced in R2020a
4-95
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b1/b2
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-96
jm_0012: Usage restrictions of events and broadcasting events
Example — Incorrect
Sub ID b1
The send syntax send(event_name, state_name) shall be used to broadcast Stateflow events.
Custom Parameter
Not Applicable
Example — Correct
4-97
4 Stateflow
Example — Incorrect
The state that receives the broadcast has not been defined in the send syntax.
4-98
jm_0012: Usage restrictions of events and broadcasting events
Sub ID b2
The send syntax send(state_name.event_name) with the qualified event name shall be used to
broadcast Stateflow events.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
The state that receives the broadcast has not been described in the send syntax.
4-99
4 Stateflow
Rationale
Sub ID a:
• Recursive processing in a chart is prevented by using Stateflow events in the Stateflow Chart
output only.
• Improves readability because transitions that are triggered by events are clearly identified.
Verification
Model Advisor check: “Check for usage of events in Stateflow charts” (Simulink Check)
Last Changed
R2024b
See Also
• “Events” (Stateflow)
• “Use Events to Execute Charts” (Stateflow)
• “Broadcast Local Events to Synchronize Parallel States” (Stateflow)
Version History
Introduced in R2020a
4-100
jc_0733: Order of state action types
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
entry (en)
during (du)
exit (ex)
Custom Parameter
Not Applicable
4-101
4 Stateflow
Example — Correct
Example — Incorrect
4-102
jc_0733: Order of state action types
Sub ID b
entry (en)
during (du)
exit (ex)
Custom Parameter
Not Applicable
4-103
4 Stateflow
Example — Correct
Example — Incorrect
4-104
jc_0733: Order of state action types
Rationale
Sub ID a:
Verification
Model Advisor check: “Check order of state action types” (Simulink Check)
Last Changed
R2020a
See Also
• “Represent Operating Modes by Using States” (Stateflow)
• “During Actions” (Stateflow)
• “Exit a State” (Stateflow)
Version History
Introduced in R2020a
4-105
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
State action types shall not be used more than one time in a Stateflow state.
Custom Parameter
Not Applicable
Example — Correct
4-106
jc_0734: Number of state action types
Example — Incorrect
Rationale
Sub ID a:
• The execution order will differ depending on the order in which they are described.
• Execution order can be difficult to understand when the action type is described multiple times.
Verification
Model Advisor check: “Check repetition of action types” (Simulink Check)
Last Changed
R2020a
See Also
• “Represent Operating Modes by Using States” (Stateflow)
Version History
Introduced in R2020a
4-107
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
This example illustrates how the model behavior in Stateflow Chart is misinterpreted. It appears that
TBD is output when state action type exit(ex) is used, but it is in fact being overwritten by the state
action type entry of the transition destination state. It is not outputted by the Stateflow Chart.
4-108
jc_0740: Limitation on use of exit state action
Rationale
Sub ID a:
• Execution timing can be difficult to understand when state action type exit(ex) is used in
combination with a conditional action, a transition action, or state action type entry(en). This
can result in misinterpretation of the model behavior.
Verification
Model Advisor check: “Check if state action type 'exit' is used in the model” (Simulink Check)
Last Changed
R2020a
See Also
• “Exit a State” (Stateflow)
Version History
Introduced in R2020a
4-109
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a1, a2, b
MATLAB Versions
All
Rule
Sub ID a1
Variables that are used in a state transition condition shall not use state action du to perform an
update.
Custom Parameter
Not Applicable
Exceptions
This rule applies exclusively to writing in a state chart with a transition source. The update is not
prohibited for parallel states and outside of the chart.
4-110
jc_0741: Timing to update data used in state chart transition conditions
Example — Correct
Example — Incorrect
Sub ID a2
Variables that are used in a state transition condition shall use state action du to perform an update.
4-111
4 Stateflow
Custom Parameter
Not Applicable
Exceptions
This rule applies exclusively to writing in a state chart with a transition source. The update is not
prohibited for parallel states and outside of the chart.
Example — Correct
4-112
jc_0741: Timing to update data used in state chart transition conditions
Example — Incorrect
Sub ID b
When the data referenced in a transition condition is updated to du as its source state, mixing
updated and non-updated data in the same transition condition is prohibited, except for constants and
parameters.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
State action du is used to perform an update. There is a mixture of data to update with State action
du(b) and data not updated in2.
4-113
4 Stateflow
Rationale
Sub ID a1:
• The execution order of the transition condition and implement of during can be difficult to
understand, which increases the risk of errors.
Verification
Model Advisor check: “Check updates to variables used in state transition conditions” (Simulink
Check)
Last Changed
R2024b
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Represent Operating Modes by Using States” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
Version History
Introduced in R2020a
4-114
jc_0772: Execution order and transition conditions of transition lines
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
4-115
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
• An unconditional transition that is in a position other than the last in the execution order causes
the subsequent transition to be a dead path, which results in unintended simulation behavior.
Verification
Model Advisor check: “Check usage of transition conditions in Stateflow transitions” (Simulink
Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Types of Chart Execution” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
Version History
Introduced in R2020a
4-116
jc_0753: Condition actions and transition actions in Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
4-117
4 Stateflow
Sub ID b
Condition actions and transition actions shall not be combined in the same Stateflow Chart.
Custom Parameter
Not Applicable
Example — Correct
Either a condition action or a transition action can be used. (The following diagram illustrates a
transition action.)
Example — Incorrect
Rationale
Sub ID a:
4-118
jc_0753: Condition actions and transition actions in Stateflow
Sub ID b:
• A condition action executes upon entering a transition. A transition action executes after
determining whether it can transition to the next state. Adherence to the rule prevents confusion
between a conditional action and a transition action.
Verification
Model Advisor check: “Check condition actions and transition actions in Stateflow” (Simulink Check)
Last Changed
R2024b
See Also
• “Evaluate Outer Transitions with Condition and Transition Actions” (Stateflow)
Version History
Introduced in R2020a
4-119
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Variables, constants, or parameters in Stateflow Chart shall not be used to perform division
operations.
Custom Parameter
Not Applicable
Example — Correct
4-120
jc_0711: Division in Stateflow
Example — Incorrect
Sub ID a2
When division occurs in a Stateflow Chart, the process shall prevent division by zero.
Custom Parameter
Not Applicable
Example — Correct
4-121
4 Stateflow
Example — Incorrect
Rationale
Sub ID a1, a2:
• Deviation from the rule can cause unintended operation and code generation results.
Verification
Model Advisor check: Adherence to this modeling guideline cannot be verified by using a Model
Advisor check.
4-122
jc_0711: Division in Stateflow
Last Changed
R2020a
See Also
• “Fixed-Point Operations in Stateflow Charts” (Stateflow)
Version History
Introduced in R2020a
4-123
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-124
db_0127: Limitation on MATLAB commands in Stateflow blocks
Example — Incorrect
Sub ID b
When a built-in MATLAB function is used in Stateflow blocks, it shall be accessed only by using
MATLAB Function.
Supplement
Not Applicable
4-125
4 Stateflow
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
• Not all built-in MATLAB functions are supported for code generation. As a result, code may not be
generated for these unsupported MATLAB functions.
Sub ID b:
4-126
db_0127: Limitation on MATLAB commands in Stateflow blocks
• Not all built-in MATLAB functions are supported for code generation. As a result, code may not be
generated for these unsupported MATLAB functions.
• Readability improves when C and MATLAB action languages are described separately.
Verification
Model Advisor check: “Check for MATLAB expressions in Stateflow charts” (Simulink Check)
Last Changed
R2024b
See Also
• MATLAB Function
• “Stateflow Programmatic Interface” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Version History
Introduced in R2020a
4-127
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
• ==
• !=
• ~=
• <>
Custom Parameter
Not Applicable
Example — Correct
4-128
jc_0481: Use of hard equality comparisons for floating point numbers in Stateflow
Example — Incorrect
Rationale
Sub ID a:
• Due to the nature of the floating-point data type, as it contains an error, the result of the
equivalence comparison operation may be false when it was expected to be true.
Verification
Model Advisor check: “Check usage of floating-point expressions in Stateflow charts” (Simulink
Check)
Last Changed
R2024b
4-129
4 Stateflow
See Also
• “Fixed-Point Data in Stateflow Charts” (Stateflow)
• “Relational Operations”
Version History
Introduced in R2020a
4-130
na_0001: Standard usage of Stateflow operators
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b1/b2/b3, c
MATLAB Versions
All
Rule
Sub ID a
When Stateflow Chart property Action Language is set to C, operators (&, |, ^, ~) shall be used only
for bit operations.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-131
4 Stateflow
Sub ID b1
When Stateflow Chart property Action Language is set to C, operator ~= shall be used for inequality
operations.
Custom Parameter
Not Applicable
Example — Correct
Sub ID b2
When Stateflow Chart property Action Language is set to C, operator != shall be used for inequality
operations.
Custom Parameter
Not Applicable
4-132
na_0001: Standard usage of Stateflow operators
Example — Correct
Sub ID b3
When Stateflow Chart property Action Language is set to C, operator <> shall be used for inequality
operations.
Custom Parameter
Not Applicable
Example — Correct
Sub ID c
When Stateflow Chart property Action Language is set to C, operation ! shall be used for logical
negation.
Custom Parameter
Not Applicable
Example — Correct
4-133
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
&& and &, || ,and |, have the same calculation function. However, when && and & or || and | are
combined in the same chart, it can be difficult to determine whether these are separate
calculation functions or the same calculation function.
Sub ID c:
Verification
Model Advisor check: “Check Stateflow operators” (Simulink Check)
Last Changed
R2020a
See Also
• “Modify the Action Language for a Chart” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Version History
Introduced in R2020a
4-134
jc_0655: Prohibition of logical value comparison in Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-135
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
4-136
jc_0655: Prohibition of logical value comparison in Stateflow
Verification
Model Advisor check: “Check prohibited comparison operation of logical type signals” (Simulink
Check)
Last Changed
R2020a
Version History
Introduced in R2020a
4-137
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
Negative values cannot be input into 16-bit environments. (Negative values can be input into 32-bit
environments.)
4-138
jc_0451: Use of unary minus on unsigned integers
Rationale
Sub ID a:
• As the results are depend on the execution environment, unintended results can occur.
Verification
Model Advisor check: “Check usage of unary minus operations in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Data Types Supported by Simulink”
• Unary Minus
Version History
Introduced in R2020a
4-139
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
All operations, including substitution, comparison, arithmetic, etc., shall be performed between
variables of the same data type.
The data type of the actual arguments and the formal arguments in a function call shall be the same.
Custom Parameter
Not Applicable
Example — Correct
4-140
jc_0802: Prohibited use of implicit type casting in Stateflow
Variables have different data types but are explicitly typecast before calculation.
The data type of actual arguments and formal arguments in the function call are the same.
Example — Incorrect
4-141
4 Stateflow
Calculations are performed between unsigned integer type variables and signed integers.
The data type of actual arguments and formal arguments in the function call are different.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for implicit type casting in Stateflow” (Simulink Check)
Last Changed
R2020a
See Also
• “Type Cast Operations” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
4-142
jc_0802: Prohibited use of implicit type casting in Stateflow
Version History
Introduced in R2020a
4-143
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2, b1/b2, c1/c2,
• JMAAB — a1/a2, b1/b2, c1/c2, d1/d2
MATLAB Versions
All
Rule
Sub ID a1
A minimum value for the signed integer type shall not be provided when using the abs library
function.
Custom Parameter
Not Applicable
Example — Correct
4-144
jc_0803: Passing values to library functions
Example — Incorrect
Sub ID a2
Not Applicable
Sub ID b1
A negative number shall not be entered when using the sqrt library function.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID b2
4-145
4 Stateflow
Custom Parameter
Not Applicable
Sub ID c1
A negative number shall not be entered when using the log and log10 library functions.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID c2
Custom Parameter
Not Applicable
Sub ID d1
Zero shall not be entered for the second argument when using the fmod library function.
Custom Parameter
Not Applicable
4-146
jc_0803: Passing values to library functions
Example — Correct
Example — Incorrect
Sub ID d2
Not Applicable
Rationale
Sub IDs a1, b1, c1, d1:
• The behavior of a library function when an invalid value has been passed is dependent on the
processing system and may result in unintended behavior.
• To avoid duplicate modeling of the same guard process in Simulink and Stateflow, use Simulink to
perform arithmetic operations
Verification
Model Advisor check: Adherence to this modeling guideline cannot be verified by using a Model
Advisor check.
Last Changed
R2020a
4-147
4 Stateflow
See Also
• “Library Development” (Embedded Coder)
Version History
Introduced in R2020a
4-148
Label Description
Label Description
4-149
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
An identical name shall not be used for states, data (inputs and outputs, local data, constants,
parameters, data store memory), or event names in a single Stateflow Chart.
Custom Parameter
Not Applicable
4-150
jc_0732: Distinction between state names, data names, and event names
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check uniqueness of Stateflow state, data and event names” (Simulink Check)
4-151
4 Stateflow
Last Changed
R2020a
Version History
Introduced in R2020a
4-152
jc_0730: Unique state name in Stateflow blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The content of linked atomic subcharts can be treated as another Stateflow Chart block.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Readability is impaired.
• Deviation from the rule can cause unintended code behavior.
Verification
Model Advisor check: “Check uniqueness of State names” (Simulink Check)
Last Changed
R2020a
4-153
4 Stateflow
See Also
• “Represent Operating Modes by Using States” (Stateflow)
• “Atomic Subcharts” (Stateflow)
Version History
Introduced in R2020a
4-154
jc_0731: State name format
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The state name shall be followed by a new line that does not include a slash (/).
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
4-155
4 Stateflow
Verification
Model Advisor check: “Check usage of State names” (Simulink Check)
Last Changed
R2020a
See Also
• “Represent Operating Modes by Using States” (Stateflow)
Version History
Introduced in R2020a
4-156
jc_0501: Format of entries in a State block
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
A state action statement shall not be written on the same line as a state action type.
Custom Parameter
Not Applicable
Example — Correct
4-157
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
• Readability is impaired.
Verification
Model Advisor check: “Check entry formatting in State blocks in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Represent Operating Modes by Using States” (Stateflow)
Version History
Introduced in R2020a
4-158
jc_0736: Uniform indentations in Stateflow blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
State action types shall not have blank spaces at the start of a line.
Executable statements shall have one single-byte space at the start of the line.
Custom Parameter
Executable statements use one single-byte space at the start of the line.
4-159
4 Stateflow
Example — Incorrect
Executable statements do not have a single-byte space at the start of the line.
Sub ID b
• [ of a transition condition
• { of a condition action
• / of a transition action
Custom Parameter
Not Applicable
Example — Correct
A blank space is not entered before the [ and { of the transition label condition, condition action, and
transition action.
Example — Incorrect
A blank space is entered before the [ and { of the transition label condition, condition action, and
transition action.
4-160
jc_0736: Uniform indentations in Stateflow blocks
Sub ID c
At least one single-byte space shall be entered after the / of a transition action.
Custom Parameter
Example — Incorrect
Rationale
Sub ID a:
• Using uniform indents before the executable statement clarifies the link between the state action
type of a state label and the execution statement, improving readability.
Sub ID b:
• Using uniform indents for transition conditions, condition actions, and transition actions improves
readability.
Sub ID c:
4-161
4 Stateflow
Verification
Model Advisor check: “Check indentation of code in Stateflow states” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-162
jc_0770: Position of transition label
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a1/a2/a3
MATLAB Versions
All
Rule
Sub ID a1
Transition labels are positioned near the source of the transition line.
Custom Parameter
Not Applicable
Example — Correct
4-163
4 Stateflow
Example — Incorrect
The positioning of transition labels is inconsistent and do not correspond to the transition line.
Sub ID a2
Transition labels are positioned near the center of the transition line.
Custom Parameter
Not Applicable
Example — Correct
Transition labels are positioned near the center of the transition line.
4-164
jc_0770: Position of transition label
Example — Incorrect
The positioning of transition labels is inconsistent and do not correspond to the transition line.
Sub ID a3
• Transition labels including transition conditions shall be placed near the source of transition lines.
• Transition labels without transition conditions shall be placed near the destination of transition
lines.
4-165
4 Stateflow
Exception
Not Applicable
Example — Correct
Transition labels including transition conditions are placed near sources of transition lines and those
without transition conditions are placed near destinations of transition lines.
Example — Incorrect
Transition labels without transition conditions are not placed near destinations of transition lines.
Rationale
Sub IDs a1, a2:
• Consistent positioning of transition labels makes the correspondence between label and line
easier to understand.
Verification
Model Advisor check: “Check placement of Label String in Transitions” (Simulink Check)
4-166
jc_0770: Position of transition label
Last Changed
R2024b
See Also
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-167
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Comments in transition labels shall be positioned above transition conditions, condition actions,
transition actions, and Stateflow events.
Custom Parameter
Not Applicable
Example — Correct
4-168
jc_0771: Comment position in transition labels
Example — Incorrect
Sub ID a2
Comments in transition labels shall be positioned below transition conditions, condition actions,
transition actions, and Stateflow events.
Custom Parameter
Not Applicable
Example — Correct
4-169
4 Stateflow
Example — Incorrect
Rationale
Sub IDs a1, a2:
Verification
Model Advisor check: “Check position of comments in transition labels” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
• “Add Descriptive Comments in a Chart” (Stateflow)
Version History
Introduced in R2020a
4-170
jc_0752: Condition action in transition label
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Parentheses in condition actions shall use only curly brackets on a single line.
Not Applicable
Example — Correct
Note: The example is for a flow chart, but the rule also applies to state transitions.
Example — Incorrect
4-171
4 Stateflow
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of parentheses in Stateflow transitions” (Simulink Check)
Last Changed
R2020a
See Also
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-172
jc_0774: Comments for through transition
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When there is no processing within an unconditional transition, a clarifying comment shall be written
on the transition label.
Custom Parameter
Not Applicable
Example — Correct
4-173
4 Stateflow
Example — Incorrect
A clarifying comment is not provided on the condition path, so it is difficult to determine whether the
lack of action is intentional.
4-174
jc_0774: Comments for through transition
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for comments in unconditional transitions” (Simulink Check)
Last Changed
R2020a
See Also
• “Add Descriptive Comments in a Chart” (Stateflow)
• “Transition Between Operating Modes” (Stateflow)
Version History
Introduced in R2020a
4-175
4 Stateflow
Miscellaneous
4-176
jc_0511: Return values from a graphical function
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The return value for graphical functions shall be set in one place only.
Custom Parameter
Not Applicable
Example — Correct
4-177
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
• Modifications to the output name is limited to prevent the changes from being missed or
overlooked.
Verification
Model Advisor check: “Check return value assignments in Stateflow graphical functions” (Simulink
Check)
Last Changed
R2020a
See Also
• “Create Flow Charts in Stateflow” (Stateflow)
• “Create Flow Charts by Using Pattern Wizard” (Stateflow)
4-178
jc_0511: Return values from a graphical function
Version History
Introduced in R2020a
4-179
4 Stateflow
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Calls from a graphical function to itself and calls between graphical functions shall be prohibited.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-180
jc_0804: Prohibited use of recursive calls with graphical functions
Rationale
Sub ID a:
• Readability decreases. Deviation from the rule can cause unintended overflows and infinite loops.
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check. For more
information, see “Check usage of graphical functions in Stateflow” (Simulink Check).
Last Changed
R2020a
See Also
• “Reuse Logic Patterns by Defining Graphical Functions” (Stateflow)
• “How Stateflow Objects Interact During Execution” (Stateflow)
4-181
4 Stateflow
Version History
Introduced in R2020a
4-182
na_0042: Usage of Simulink functions
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
When using a Simulink Function block in a Stateflow Chart, one or more of the following conditions
shall be met:
• Input/output variables shall use only local Stateflow Chart data and input data in the Simulink
Function block.
• The Simulink Function block shall be called from multiple places in the Stateflow Chart.
• The Simulink Function block shall not be called at every time step.
Custom Parameter
Not Applicable
Example — Correct
The Simulink Function block lookup1D is not called from every time step and, therefore, can be used.
4-183
4 Stateflow
Example — Incorrect
The Simulink Function block lookup1D is called from every time step and, therefore, cannot be used
(out is the Stateflow output data)
Rationale
Sub ID a:
• To improve model readability, the use of the Simulink Function block should be used with caution
in charts.
Verification
Model Advisor check: “Check usage of Simulink function in Stateflow” (Simulink Check)
Last Changed
R2020a
See Also
• “Simulink Functions Overview”
• “Define a Simulink Function in a Model”
Version History
Introduced in R2020a
4-184
na_0039: Limitation on Simulink functions in Chart blocks
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Stateflow blocks shall not be used in Simulink Function blocks that are included in a Stateflow Chart.
Custom Parameter
Not Applicable
4-185
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check use of Simulink in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• “Simulink Functions Overview”
• “Define a Simulink Function in a Model”
4-186
na_0039: Limitation on Simulink functions in Chart blocks
Version History
Introduced in R2020a
4-187
5
MATLAB
MATLAB Appearance
5-2
na_0025: MATLAB Function header
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
• Function name
• Description of function
• Assumptions and limitations
• Description of changes from previous versions
• Lists of inputs and outputs
Custom Parameter
Not Applicable
Example
5-3
5 MATLAB
Rationale
Sub ID a:
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
Last Changed
R2020a
See Also
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
Version History
Introduced in R2020a
5-4
na_0018: Number of nested if/else and case statement
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
The number of nested levels in if /else and case statements shall be limited, typically to three
levels.
Custom Parameter
Rationale
Sub ID a:
• Improves readability
• Code generation may not be possible.
Verification
Model Advisor check: “Check nested conditions in MATLAB Functions” (Simulink Check)
Last Changed
R2020a
5-5
5 MATLAB
See Also
• “Loops and Conditional Statements”
Version History
Introduced in R2020a
5-6
MATLAB Data and Operations
5-7
5 MATLAB
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Signal lines shall be used to connect data that is shared between MATLAB Function blocks.
Custom Parameter
Not Applicable
Example — Correct
5-8
na_0024: Shared data in MATLAB functions
HIGHRPMFAULT = 2^1;
LOWRPMFAULT = 2^2;
ErrorFlag = ErrorFlag_In;
if EngineData > RPM_HIGH
ErrorFlag = bitor(ErrorFlag,HIGHRPMFAULT);
end
if EngineData < RPM_LOW
ErrorFlag = bitor(ErrorFlag,LOWRPMFAULT);
end
Example — Incorrect
function EngineFaultEvaluation(EngineData)
%#codegen
global ErrorFlag_DataStore
RMP_HIGH = 10000;
RMP_LOW = 10;
HIGHRPMFAULT = 2^1;
LOWRPMFAULT = 2^2;
if EngineData > RPM_HIGH
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore,HIGHRPMFAULT);
end
if EngineData < RPM_LOW
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore,LOWRPMFAULT);
end
function WheelFaultEvaluation(WheelData)
%#codegen
global ErrorFlag_DataStore
SLIP_HIGH = 1000;
WHEELSLIP = 2^3;
if WheelData > SLIP_HIGH
ErrorFlag_DataStore = bitor(ErrorFlag_DataStore,WHEELSLIP);
end
5-9
5 MATLAB
end
Rationale
Sub ID a:
• When a data store is used, the readability of the data flow decreases and can lead to errors in the
update reference timing.
Verification
Model Advisor check: “Check MATLAB code for global variables” (Simulink Check)
Last Changed
R2020a
See Also
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
• “Signal Lines”
• “Resolve Signal Objects for Output Variables”
Version History
Introduced in R2020a
5-10
na_0031: Definition of default enumerated value
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Method getDefaultValue() shall be used to explicitly define the default value of an enumeration.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
5-11
5 MATLAB
end
end
Rationale
Sub ID a:
• When an enumerated type does not have a clearly defined a default value, the first enumeration
string that is described will be defined as the default, which may not be as intended.
Verification
Model Advisor check: “Check usage of enumerated values” (Simulink Check)
Last Changed
R2020a
See Also
• “Use Enumerated Data in Simulink Models”
• “Define Enumerated Data Types” (Stateflow)
• “Instantiate Enumerations”
Version History
Introduced in R2020a
5-12
na_0034: MATLAB Function block input/output settings
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
The data type in the model explorer shall be defined for input and output to the MATLAB Function
block.
Custom Parameter
Not Applicable
Rationale
Sub ID a:
• Defining the data type for input and output to the MATLAB Function block helps prevent
simulation errors and unexpected behavior.
Verification
Model Advisor check: “Check input and output settings of MATLAB Functions” (Simulink Check)
Last Changed
R2020a
5-13
5 MATLAB
See Also
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
Version History
Introduced in R2020a
5-14
MATLAB Usage
MATLAB Usage
5-15
5 MATLAB
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
The length of MATLAB functions shall be limited. The recommended limit is 60 lines of code. Sub-
functions can use an additional 60 lines of code.
This restriction applies to MATLAB functions that reside in the Simulink block diagram and external
MATLAB files with a .m extension.
Custom Parameter
Rationale
Sub ID a:
Verification
Model Advisor check: “Check lines of code in MATLAB Functions” (Simulink Check)
Last Changed
R2020a
5-16
na_0016: Source lines of MATLAB Functions
See Also
• “Integrate MATLAB Functions in a Stateflow Charts” (Stateflow)
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
Version History
Introduced in R2020a
5-17
5 MATLAB
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
MATLAB Function blocks that reside in the Simulink block diagram level counts as the first level,
unless it is simply a wrapper for an external MATLAB file with a .m extension. This includes functions
that are defined within the block and those in separate .m files.
Exclusions
The following function types are excluded from the number of levels:
Custom Parameter
Rationale
Sub ID a:
Verification
Model Advisor check: “Check the number of function calls in MATLAB Function blocks” (Simulink
Check)
5-18
na_0017: Number of called function levels
Last Changed
R2020a
See Also
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
• “Integrate MATLAB Functions in a Stateflow Charts” (Stateflow)
• “Exponents and Logarithms”
Version History
Introduced in R2020a
5-19
5 MATLAB
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Incorrect
str = 'A';
for i = 1:u
str = [str 'B'];
end
if strcmp(str, 'ABB')
y = int16(1);
else
y = int16(0);
end
end
Rationale
Sub ID a:
5-20
na_0021: Strings in MATLAB functions
• MATLAB functions store strings as character arrays. As a result, storing strings of different
lengths in the same variable does not support dynamic memory allocation, which prevents the
strings from being stored.
Consider using enumerated types when a string is used in a Switch Case block
Verification
Model Advisor check: “Check usage of character vector inside MATLAB Function block” (Simulink
Check)
Last Changed
R2020a
See Also
• “Implement MATLAB Functions in Simulink with MATLAB Function Blocks”
• “Integrate MATLAB Functions in a Stateflow Charts” (Stateflow)
Version History
Introduced in R2020a
5-21
5 MATLAB
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
5-22
na_0022: Recommended patterns for Switch/Case statements
outVar = 1;
case Case_2
outVar = 2;
case Case_3
outVar = 3;
otherwise
outVar = 10;
end
end
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of recommended patterns for Switch/Case statements” (Simulink
Check)
Last Changed
R2020a
See Also
• “Loops and Conditional Statements”
Version History
Introduced in R2020a
5-23
5 MATLAB
Guideline Publication
Control Algorithm Modeling Guidelines - Using MATLAB, Simulink, and Stateflow
• Version 6.0
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
As comment symbols /* and */ are automatically assigned in the generated code, the symbol shall
not be used in:
Custom Parameter
Not Applicable
Example — Incorrect
5-24
jc_0801: Prohibited use of the /* and */ comment symbols
Rationale
Sub ID a:
• Since comment symbols /* and */ are automatically assigned in the generated code, comments
can be unintentionally nested and behave differently than expected.
Verification
Model Advisor check: “Check for use of C-style comment symbols” (Simulink Check)
Last Changed
R2020a
5-25
5 MATLAB
See Also
• “Code Generation Template (CGT) Files” (Embedded Coder)
• “MPT Data Object Properties” (Embedded Coder)
• “Specify Comment Style for C/C++ Code” (Embedded Coder)
• “Add Custom Comments for Variables in the Generated Code” (Embedded Coder)
Version History
Introduced in R2020a
5-26
6
Considerations
Different MATLAB versions can be used for different stages in the development process. For example,
you can generate and verify the code in R2017b and then use Simulink Design Verifier™ to develop
test cases in R2020a.
It is necessary to regularly check the bug report published by MathWorks, which are available on the
MathWorks website at https://www.mathworks.com/support/bugreports. Depending on the bug, a
version change may be required; a decision that can be reversed if necessary. During this evaluation,
it is important to consider risk from both:
It is necessary to always have a process that allows adaptation to the latest version and to
appropriately evaluate and judge what is the safest option.
6-2
Considerations for Determining Guideline Operation Rules
• Library links
• Sample Time
• (Block) Sorted execution order
• (Signals and ports) Wide Non-scalar Lines
• (Signals and ports) Port data types
See guidelines:
Usable Blocks
There are many blocks in Simulink, however, not all are suitable for all aspects of a project. For
example, only some blocks are suitable for generating production-quality code. Or, depending on the
block, a function using a combination of basic blocks can be represented by using one block. Usable
blocks and design should be defined and limited to the requirements and specifications of the project.
Significantly limiting the number of available blocks can cause adverse effects, such decreased
readability due to variation within the descriptions for the same function, decreased code efficiency,
and increased user libraries.
See guideline db_0143: Usable block types in model hierarchy for defining usable blocks
Optimization Parameters
Optimization options significantly affect generated code. Closely evaluate and apply the optimization
options with regards to how they impact the security and safety considerations for your project or
product.
For embedded automotive products, it is critical that processing time is fast and RAM/ROM
requirement are minimal. To accommodate these requirements, optimization parameters are applied
on the Conditional Input Branch Execution pane. These optimization parameters improve the
computation rate by executing only where the condition holds during execution of the conditional
branch by using the Switch block.
In contrast, for the aviation industry, the Conditional Input Branch Execution pane is disabled
because stabilizing the execution speed is key. Calculation on both sides is preferred in order to
maintain a stable computation time, even if calculation is needed only on the side where the condition
holds.
6-3
6 Considerations
Configuration Parameters
Describes model system hardware characteristics, including products and test hardware
configuration setup for simulation and code generation. Configure these parameters so they are
compatible with the microcomputer that the project uses. Unintended utility functions can be
inserted if signed integer division rounding is undefined.
Specified when using model references. Refers to options to include other models in this model,
options to include this model in another model, and build options of simulation and code generation
targets.
Configures a simulation target of a model with MATLAB Function, Stateflow Chart (Stateflow), or
Truth Table (Stateflow) blocks.
For additional information about the high-integrity configuration settings, see “Configuration
Parameter Considerations” in the “High-Integrity System Modeling” guidelines.
For additional information the about the code generation configuration settings, see the “Code
Generation” modeling guidelines.
6-4
Considerations for Applying Guidelines to a Project
• “Using the Model Analysis Process When Applying Guidelines” on page 6-5
• “Adoption of the Guideline Rule and Process Settings” on page 6-5
• “Setting the Guideline Rule Application Field and the Clarifying the Exclusion Condition” on page
6-5
• “Parameter Recommendations in the Guidelines” on page 6-6
• “Verifying Adherence to the Guidelines” on page 6-6
• “Modifying Adherence to the Guidelines” on page 6-6
For example, the analysis of a simple model can use function sldiagnostics to investigate how
often a specific block is used. Adjust the operation rules list by specifying blocks that are frequently
used and those that are not.
Setting the Guideline Rule Application Field and the Clarifying the
Exclusion Condition
The field to which the guidelines apply must be determined. For example, guidelines can be:
6-5
6 Considerations
• Specific to fields where general engineers edit the models. The intention of these rules is to
ensure that the models are easily understandable in those fields.
Note Specialized fields can be excluded from the constraints of these guidelines by limiting the
scope and applying unique set of guidelines that are specific in this environment.
Specialized fields, such as those where modelers design custom library blocks, are not typically
targeted by these guidelines.
Furthermore, when having a control model that is operated with Rapid Control Prototyping (RCP) ,
the entire model should not be set as a target; instead, the field needs to be limited. It is necessary to
generate the code and review the areas that are implemented in the built-in microcomputer as well as
the areas that are not. These guidelines do not apply to control models such as those scheduler
models that are made solely for RCP and are not implemented, or for interface sections with blocks
that correspond to drivers such as CAN and PWM signals for operating actual machines.
The decision whether to use an automated checking mechanism (third part or internal) or perform
manual checks is very important. Also, the stage at which the checks occur, as well as developing a
system for revising the check rule criteria, is important.
Automated checking can significantly reduce the time required for review. It is recommended that an
additional, manual review also be performed by a skilled person, even if everything can be checked
automatically.
When evaluating the change request, first listen to the needs of the modeler and determine the root
cause of the request. When the request is based on the user not understanding block usage or a
guideline rule, training should occur instead of revising the rule.
The procedure to relax the rules as needed should be implemented when there are restrictions due to
company objectives and control specifications or hardware (such as microcomputers).
6-6
A
• Layer concepts shall be assigned to layers and subsystems shall be divided accordingly.
• When a layer concept is not needed, it does not need to be allocated to a layer.
• Multiple layer concepts can be allocated to one layer.
When building hierarchies, division into subsystems for the purpose of saving space within the layer
shall be avoided.
Top Layer
• Simple control model — Represents both the function layer and schedule layer in the same layer.
Here, function is execution unit. For example, a control model has only one sampling cycle and all
functions are arranged in execution order.
• Complex control model Type α — The schedule layer is positioned at the top. This method makes
integration with the code easy, but functions are divided, and the readability of the model is
impaired.
• Complex control model Type β — Function layers are arranged at the top and schedule layers are
positioned below the individual function layers.
A-2
Understanding Model Architecture
• Subsystems shall be divided by function, with the respective subsystems representing one
function.
• One function is not always an execution unit so, for that reason, the respective subsystem is
not necessarily an atomic subsystem. In the type β example below, it is more appropriate for a
function layer subsystem to be a virtual subsystem. Algebraic loops are created when these
change into atomic subsystems.
• Individual functional units shall be described.
• When the model includes multiple large functions, consider using model references for each
function to partition the model.
A-3
A Understanding Model Architecture
Schedule Layers
• System sampling intervals and execution priority shall be set. Use caution when setting multiple
sampling intervals. In connected systems with varying sampling intervals, ensure that the system
is split for each sampling interval. This minimizes the RAM needed to store previous values in the
situation where the processing of signals values differs for fast cycles and slow cycles.
• Priority ranking shall be set. This is important when designing multiple, independent functions.
When possible, computation sequence for all subsystems should be based on subsystem
connections.
• Two different types of priority rankings shall be set, one for different sampling intervals and the
other for identical sampling rates.
There are two types of methods that can be used for setting sampling intervals and priority rankings:
• For subsystems and blocks, set the block parameter sample time and block properties priority.
• When using conditional subsystems, set independent priority rankings to match the scheduler.
Patterns exist for many different conditions, such as the configuration parameters for custom
sampling intervals, atomic subsystem settings, and the use of model references. The use of a specific
pattern is closely linked to the code implementation method and varies significantly depending on the
status of the project. Models that are typically affected include:
A-4
Understanding Model Architecture
• Number of models (and whether there is more than one set of generated code)
In the hierarchy, the control layer expresses all input processing, intermediate processing, and output
processing by using one function. The arrangement of blocks and subsystems is important in this
layer. Multiple, mixed small functions should be grouped by dividing them between the three largest
stages of input processing, intermediate processing and output processing, which forms the
conceptual basis of control. The general configuration occurs close to the data flow layer and is
represented in the horizontal line. The difference in a data flow layer is its construction from multiple
subsystems and blocks.
In control flow layers, the horizontal direction indicates processing with different significance; blocks
with the same significance are arranged vertically.
A-5
A Understanding Model Architecture
Block groups are arranged horizontally and are given a provisional meaning. Red borders, which
signify the delimiter for processing that is not visible, correspond to objects called virtual objects.
Using annotations to mark the delimiters makes it easier to understand.
A-6
Understanding Model Architecture
Control flow layers can co-exist with blocks that have a function. They are positioned between the
sub-function layer and the data flow layer. Control flow layers are used when:
Placement in the hierarchy organizes the internal layer configuration and makes it easier to
understand. It also improves maintainability by avoiding the creation of unnecessary layers.
When the model consists solely of blocks and does not include a mix of subsystems, if the horizontal
layout can be split into input/intermediate/output processing, it is considered a control flow layer.
Selection Layers
When a subsystem has switch functions that allow only one subsystem to run depending on the
conditional control flow inside the red border, it is referred to as a selection layer. It is also described
as a control flow layer because it structures input processing/intermediate processing (conditional
control flow)/output processing.
A-7
A Understanding Model Architecture
In the control flow layer, the horizontal direction indicates processing with different significance.
Parallel processing with the same significance is structured vertically. In selection layers, no
significance is attached to the horizontal or vertical direction, but they show layers where only one
subsystem can run. For example:
A data flow layer is the layer below the control flow layer and selection layer.
A data flow layer represents one function as a whole; input processing, intermediate processing and
output processing are not divided. For instance, systems that perform one continuous computation
that cannot be split.
Data flow layers cannot coexist with subsystems apart from those where exclusion conditions apply.
Exclusion conditions include:
A-8
Understanding Model Architecture
When input processing and intermediate processing cannot be clearly divided as described above,
they are represented as a data flow layer.
A data flow layer becomes complicated when both the feed forward reply and feedback reply from the
same signal are computed at the same time. Even when the number of blocks in this type of cases is
large, the creation of a subsystem should not be included in the design when the functions cannot be
clearly divided. When meaning is attached through division, it should be designed as a control flow
layer.
A-9
A Understanding Model Architecture
• The extent to which the Simulink model will model the functions
• How the generated code is embedded
• The schedule settings on the embedded micro controller
The configuration is affected significantly when the tasks of the embedded micro controller differs
from those modeled by Simulink.
A single-task scheduler performs all processing by using basic sampling. Therefore, when processing
of longer sampling is needed, the function is split so the CPU load is as evenly distributed as possible,
and then processed using basic sampling. However, as equal splitting is not always possible, functions
may not be able to be allocated to all cycles.
For example, basic sampling is 2 millisecond, and sampling rates of 2 millisecond, 8 millisecond and
10 millisecond exist within the model. An 8 millisecond function is executed once for every four 2
millisecond cycles, and a 10 millisecond function is executed once for every five. The number of
executions is counted every 2 millisecond and the sampling function specified by this frequency is
executed. Attention needs to be paid to the fact that the 2 millisecond, 8 millisecond and 10
millisecond cycles are all computed with the same 2 millisecond. Because all computations need to be
completed within 2 millisecond, the 8 millisecond and 10 millisecond functions are split into several
and adjusted so that all 2 millisecond computations are of an almost equal volume.
The following diagram shows the 8 millisecond function split into 4 and the 10 millisecond function
split into 5.
A-10
Understanding Model Architecture
A-11
A Understanding Model Architecture
A-12
Understanding Model Architecture
It is important that computations are completed within the cycle, including slow tasks. When the
processing of a high priority computation finishes and the CPU is available, the computation for
the system with the next priority ranking begins. A high priority computation process can
interrupt a low priority computation, which is then aborted so the high priority computation
process can execute first.
If subsystem B with a 20 millisecond sampling interval uses the output of subsystem A with a 10
millisecond sampling interval, the output result of subsystem A can change while subsystem B is
computing. If the values change partway through, the results of subsystem B’s computation may not
be as expected. For example, a comparison is made in subsystem B’s first computation with the
subsystem A output, and the result is computed with the conditional judgment based on this output.
At this point, the comparison result is true. It is then compared again at the end of subsystem B; if the
output from A is different, then the result of the comparison can be false. Generally, in this type of
function development it may happen that the logic created with true, true has become true, false, and
an unexpected computation result is generated. To avoid this type of malfunction, when there is a
change in task, output results from subsystem A are fixed immediately before they are used by
subsystem B as they are used in a different RAM from that used by the subsystem A output signals. In
other words, even if subsystem A values change during the process, the values that subsystem B are
looking at is in a different RAM, so no effect is apparent.
When a model is created in Simulink and a subsystem is connected that has a different sampling
interval in Simulink, Simulink automatically reserves the required RAM.
However, if input values are obtained with a different sampling interval through integration with
hand-coded code, the engineer who does the embedding work should design these settings. For
example, in the RTW concept using AUTOSAR, different RAMs are all defined at the receiving and
exporting side.
A-13
A Understanding Model Architecture
Signal values are the same within the same 2 millisecond cycle, but when there are different 2
millisecond cycles, the computation value differs from the preceding one. When Function 2-1 and 2-2
uses signal A of Function 1, be aware that 2-1 and 2-2 uses results from different times.
For multi-task, you cannot specify at what point to use the computation result to use. With multi-task,
always store signals for different tasks in new RAM.
Before new computations are performed within the task, all values are copied.
A-14
Understanding Model Architecture
A-15
A Using Simulink and Stateflow in Modeling
Either Simulink or Stateflow can be used to model specific parts of control, however, the application
of either product in the development workflow is based on the user’s understanding of the underlying
algorithms and, ultimately, comes down to the organization to determine which tool is best suited for
their needs. Determining whether Simulink or Stateflow should be used for design should be
determined by a group of people in accordance with the task. Whether implementation in Stateflow is
done by using state transitions or with flow charts should also be specified.
In most cases, Stateflow is less efficient with regards to RAM. Therefore, Simulink has an advantage
in computations that use simple formulas. In addition, Simulink is more advantageous for situations
where state variables are operated with simple flip-flops and the Relay block. When evaluating
whether to use Simulink or Stateflow in a project, these topics should be taken into consideration:
• Increasing RAM: There must always be a RAM available for visualization of Stateflow inputs,
outputs and internal variables.
• Equation error handling: When general computational formulas are used internally, the user
designs ways to prevent overflow.
• Splitting and separating functions: When performing calculations that use Simulink outside of
Stateflow, there is a possibility that they may split, thus reducing readability. There are also times
where readability may improve. This can be difficult to judge.
There are cases where Stateflow has more efficient code than Simulink for optimum expressions that
are close to code, but most of these result in a model that is difficult to understand. If code already
exists, it is more advantageous to use S-functions instead of Stateflow modelling. Stateflow can note
computations where specific arrangements are specified, or computations using for-loops, more
efficiently than Simulink, but in recent years it has also become convenient to use MATLAB language
for descriptions. If needed, consider using MATLAB language for modelling.
For Stateflow models, when dealing with states as described below, readability improves by
describing them as state transitions:
For instance, in flip-flop circuits, different values are outputted for inputs. State variables are limited
to 0 and 1. However, a meaningful name cannot be added to each state simply by retaining boolean
type numbers. There is also no distinction between initialization and execution within the state. Thus,
only one flip-flop applies out of the four above, so Simulink is more beneficial.
In Stateflow, situations that can be represented as states are implemented as state transitions and
conditional branches that are not states are implemented as flow charts. Truth tables are classified as
a conditional branch implementation method. When designing states as state transitions by using
Stateflow, Classic should be selected as the state machine type so that it is implemented as
software into the control system’s embedded micro controller.
A-16
Using Simulink and Stateflow in Modeling
HDL Coder™ is supported by Stateflow. When using HDL Coder, Mealy or Moore must be selected;
Moore mode is more appropriate when protection is required against internal electric leaks.
Note HDL Coder use cases are not described in these guidelines.
Simulink Functionality
This section provides information about using Simulink for modeling.
Blocks with state variables are primarily grouped into Simulink and discrete types.
For most of these blocks, the user can set the state attributes and initial values by using the block
parameters. A conditional subsystem can have state variables, depending on the structure pattern.
In this example, the Tapped Delay block does not have state attributes.
A-17
A Using Simulink and Stateflow in Modeling
The Switch block and conditional subsystems behave differently when state variables are used.
Depending on the configuration setting, when any state variable exists, the Switch block generally
executes subsystem A when the condition of the control port is satisfied. If the condition is not
satisfied, it executes only subsystem B without calculating subsystem A. However, when the
subsystem A contains a state variable, calculation for the state variable within the subsystem A is
processed even when the conditions of the control port are not satisfied.
A-18
Using Simulink and Stateflow in Modeling
In the conditional subsystem, subsystem A is calculated when the condition is satisfied. When it is not
satisfied, subsystem B is calculated instead of subsystem A, regardless of the existence of any state
variables in subsystem A.
The reset action in a recalculation can be specified by using the {Action Port} setting.
The behavior of subsystem A when using a Switch block and a conditional control flow is listed in the
following tables. Familiarize yourself with these behaviors to determine which structure, the Switch
block, or conditional subsystem is most suitable for the intended purpose.
State variables
Hold No Executed Executed
Yes
Not hold No Not executed Not executed
Yes Minimally-processed
*Executed calculations
related to the state
variables
A-19
A Using Simulink and Stateflow in Modeling
See guidelines:
Subsystems
Subsystems can also be used for other purposes. Usage methods that are not functional subsystems
include:
• Mask display of the subsystem is used to describe the outline or display fixed form documents,
such as "classified"
• The open functions (callback functions in the block properties) of the subsystem is used for
running several tools or displaying explanatory text separate from the model
• Subsystems whose setting have changed to a mask subsystem (a subsystem that was simply set to
NoReadOrWrite) by a user with administrative rights to make a change, but other users cannot
see the content.
These non-typical subsystems are outside of the scope of the guidelines and, if excluded, should be
put on an exclusion list managed within the project.
See guidelines:
There are two types of subsystems: Virtual subsystems and Atomic subsystems. The primary
difference between these subsystems is whether the subsystem is treated as a single execution unit.
The virtual subsystem is the default subsystem block.
In a model, the border for a Virtual subsystem is thin as compared the border for the Atomic
subsystem, which is thick and bold.
A-20
Using Simulink and Stateflow in Modeling
Virtual Subsystems
A block that provides a visual representation is known as a "virtual block". For example, a Mux block
that compiles several signal lines, a From block that hands out the signal, and a Goto block that
corresponds to a virtual block. Since the subsystem block in the default setting only constitutes a
visual hierarchical structure, these blocks are considered virtual blocks. The subsystem is referred to
as a virtual subsystem.
Consider a subsystem that consults an external calculation result within a subsystem, as shown in the
following example. This system is calculated from these four equations.
Atomic Subsystems
An atomic subsystem is detached from the external system and is not subject to cross-border
optimization. Atomic subsystems do not use the results of the internal calculations of each subsystem.
Therefore, interim output value will use a calculation result that is delayed by a session.
A-21
A Using Simulink and Stateflow in Modeling
• in3= temp2
• in6= temp1
Atomic subsystems prohibit the direct referencing of the interim calculation results to other
subsystems.
Signal Name
Signals can be named and are referred to as signal names. When a signal is named, that signal name
is displayed as a label. Updates to labels are reflected in the signal name and are also displayed.
The signal name can be propagated to a signal line via a branched signal line or port block and
displayed as a signal name.
See guidelines:
A-22
Using Simulink and Stateflow in Modeling
Code can be generated by associating a signal name with a signal object (Simulink object or mpt
object). Type setting is configured through the data dictionary, setting of the storage class is optional.
The recommended data type settings for these blocks include:
Individual scalar signals that compose a vector shall have common functions, data type, and units.
Signals that do not fulfill the conditions as a vector can only be grouped as a bus signal. The Bus
Selector block shall be used only with bus signal inputs. It shall not be used to extract a scalar signal
from a vector signal.
See guidelines:
A-23
A Using Simulink and Stateflow in Modeling
Enumerated Types
Enumerated type data refers to data that is restricted to a determined numerical value.
The type of blocks that can be used in an enumerated type in Simulink is limited.
To use an enumerated type, you must define the enumerate type by using .m file on MATLAB. For
additional information about defining enumeration data types, see “Use Enumerated Data in Simulink
Models”.
Stateflow Functionality
This section provides information about using Stateflow for modeling.
For additional information about the Stateflow operations, see “Operations for Stateflow Data”
(Stateflow).
See guidelines:
An entry action is represented as a flow chart in a state, which starts from a default transition and
moves to junctions through transition lines, as illustrated below. Starting from an internal transition
line allows a during action to be represented in the flow chart.
A flow chart cannot maintain its active state between updates. As a result, a flow chart always ends at
a terminating junction (a connective junction that has no valid outgoing transitions).
In contrast, a state transition diagram stores its current state in memory to preserve local data and
active state between updates. As a result, state transition diagrams can begin executing where they
left off in the previous time step. This means that state transitions are suitable for modeling reactive
or supervisory systems that depend on history.
This table defines the start and end points for a flow chart and state transition diagram.
A-24
Using Simulink and Stateflow in Modeling
This illustration shows the difference between a general flow chart and state transition diagram
Mixture of flow charts and state transition diagrams with self-transition has more strict constraints.
A-25
A Using Simulink and Stateflow in Modeling
See guidelines:
Backtrack
This example shows the behavior of transitions with junctions that force backtracking behavior in
flow charts. The chart uses implicit ordering of outgoing transitions.
Initially, state A is active and transition conditions c1, c2, and c3 are true. Transition conditions c4 is
false.
1 The chart root checks to see if there is a valid transition from state A.
There is a valid transition segment marked with the transition condition c1 from state A to a
connective junction, therefore:
There is a valid transition segment marked with the transition condition c2 from state A to a
connective junction, therefore:.
A-26
Using Simulink and Stateflow in Modeling
c Transition condition c4 is not true and, therefore, the control flow backtracks to state A.
3 The chart goes to sleep.
To resolve this issue, consider adding unconditional transition lines to terminating junctions. The
terminating junctions allow flow to end if either c3 or c4 is not true. This design leaves state A
active without executing unnecessary actions.
See guidelines:
A flow chart associated with a state can be written inside or outside of the state; however, be
attentive to the execution order and backtracking.
The following flow chart, which evaluates transition from a to b after executing the flow chart outside
the state, appears to execute the transition within the same period as that of a newer calculation.
However, the transition line to b is not evaluated if the termination point is reached by calculating the
transition outside the state. This is a state transition diagram which always stays at a.
A-27
A Using Simulink and Stateflow in Modeling
Done correctly, as shown below, the transition condition is not positioned at the termination of the
external flow chart, allowing the transition line from a to b to be evaluated after the flow chart is
executed. This enables the external flow chart to execute before the transition, and to be evaluated
using the most recent value at the instant of the transition. Note that this chart contains a dead path
where the transition condition will never hold, which can cause an error when the specification is
changed in the future. Use this chart structure with caution.
A-28
Using Simulink and Stateflow in Modeling
In contrast, the following flow chart is inside a state, which means that the internal flow chart is
always calculated when executing state a and can be described as an easily comprehensible structure
without dead paths. However, it should be noted that, as a performance characteristic, when state a
is executed, the transition from a to b is evaluated in the cycle following that in which the internal
flow chart is calculated. Due to this characteristic, the timing of the execution of calculations and
transitions for the external flow chart may be off. Use with caution.
A-29
A Using Simulink and Stateflow in Modeling
See guidelines:
Pointer Variables
This code sample is from model sf_custom. To open the model, enter the following on the MATLAB
command line:
openExample('sf_custom')
A-30
Using Simulink and Stateflow in Modeling
typedef struct {
real_T a;
int8_T b[10];
}MyStruct;
#include "my_header.h"
#include <stdio.h>
real_T my_function(real_T x)
{
real_T y;
y=2*x;
return(y);
}
gMyStructVar is not defined in Stateflow. Typically, functions of my_function are called from C
source for use in Stateflow. However, direct reference to global variables exposed by the C source is
also available from Stateflow.
Initialization
This section provides information about using initialization values.
When a signal needs to be initialized, the initial values shall be set correctly.
When initial values are set inside a block, use an initial value list that includes annotations so you can
visually confirm the initial values input.
A-31
A Using Simulink and Stateflow in Modeling
• When state variables are defined AND blocks that have state variables are used.
• Discrete block groups, such as Unit Delay and Data Store Memory, have state variables.
In the case of automatic code generation, the signal name, type, and initial value can be set for
state variables by matching it to the signal in the data dictionary (associated with Simulink signal
objects). When using a signal defined in the data dictionary for a state variable, the respective
initial values should conform to the same value.
• When using a signal defined in the data dictionary for a state variable
For discrete blocks, such as Unit Delay and Data Store Memory, settings are performed not when
using signals defined in the data dictionary for the block output line, but for the state variables
inside the block. Even when the signal name of the data dictionary is assigned to the signal line,
RAM is reserved in duplicate, which is a waste of RAM.
Example — Correct
Signal is defined for the state variables inside the block. The signal name is defined and block
parameter State name must resolve to Simulink signal object is selected.
A-32
Using Simulink and Stateflow in Modeling
Example — Incorrect
Signal is defined for the output signal of the block that has state variables. The signal name is defined
and block parameter State name must resolve to Simulink signal object is not selected.
A-33
A Using Simulink and Stateflow in Modeling
Signal objects that are defined in the Workspace can be automatically associated with signal objects
and signal names of the same name by using disableimplicitsignalresolution(modelname).
However, for state variables inside the block, they are associated with the state variables inside the
block and the signal name of the same name. If a globally set signal is associated with two variables
at the same time, it is better to perform settings so that the state variables inside a block and the
signal label on the signal line have different names, otherwise the model cannot be simulated.
When setting the initial value during initialization, the init function is called to set the signal to
either the value inside of the block or to the initial value that is defined in the data dictionary. Next,
the step function (the data flow executive function) is executed. Here, the external input value is set
as the initial value. When modelling, be attentive to the execution functions and execution timing for
initialization. This is demonstrated in the following image.
A-34
Using Simulink and Stateflow in Modeling
Initial Value Settings in a System Configuration That Would Enable Initialization Parameters
There are system configurations where, depending on their settings, initialization parameters are
enabled for combinations of conditional subsystems and Merge blocks. When initial values are
required in these combinations, either of the following modeling methods is performed:
The exception is when there are successive blocks with initial values and the settings for each block
are not needed to clearly show the signal’s initial value.
Example — Correct
Example — Correct
A-35
A Using Simulink and Stateflow in Modeling
Example — Incorrect
Despite the requirement for an initial value setting, it is not shown anywhere.
A-36
B
Modeling Knowledge
B Usage Patterns
Usage Patterns
if (If_Condition)
{
output_signal = If_Value;
}
else if (Else_If_Condition)
{
output_signal = Else_If_Value;
}
else
{
output_signal = Else_Value;
}
B-2
Usage Patterns
switch (PRNDL_Enum)
{
case 1
TqEstimate = ParkV;
break;
case 2
TqEstimate = RevV;
break;
default
TqEstimate = NeutralV;
break;
}
Case construct using a Multiport Switch block.
switch (Selection)
{
case 1:
output_signal =
look1_binlxpw(In2,y1,x1,3U);
break;
case 2:
output_signal =
look1_binlxpw(In3,y2,x2,3U);
break;
case 3:
output_signal =
look1_binlxpw(In4,y3,x3,3U);
break;
default:
output_signal =
look1_binlxpw(In5,y4,x4,3U);
break;
}
B-3
B Usage Patterns
B-4
Usage Patterns
output_signal = 1;
for (i=0; i>input_vector_size; i++) {
output_signal = output_signal *
input_vector[i];
}
Vector signal element division
output_signal = 1;
for (i=0; i>input_vector_size; i++) {
output_signal = output_signal /
input_vector[i];
}
Vector signal and parameter (scalar) addition
output_signal = 0;
for (i=0; i>input_vector_size; i++) {
output_signal = output_signal -
input_vector[i];
}
B-5
B Usage Patterns
Example — Recommended
For a simple if, elseif, else structure, use the Switch block.
Using If and If Action Subsystem blocks for a simple if, elseif, else structure.
B-6
Usage Patterns
Example — Recommended
For a complex if, elseif, else structure, use If and If Action Subsystem blocks.
B-7
B Usage Patterns
Example — Recommended
By setting the fourth level as an if action subsystem, nesting is limited to a single level.
B-8
Usage Patterns
Use atomic subsystem + function setting when the C code limit is applied. In this case, there is no
need to use the if, elseif, else action subsystem, but the configuration of the Switch block can be
split and encapsulated in the subsystem.
B-9
B Usage Patterns
Use a description method that avoids layering of nesting in the Switch block.
B-10
Usage Patterns
While provided as an example, an if action subsystem is not typically used for switching the fixed
value. In these Recommended and Not Recommended examples, the generated C code will be the
same if the user does not add a function conversion setting. (Confirmed in R2010b to R2013a) The C
code is unconstrained.
B-11
B Usage Patterns
An if action subsystem shall not be used when the associated actions do not have a status variable.
Example — Recommended
Example of a model using five levels of nesting. Layering by using a subsystem does not occur
because there is no internal state.
B-12
Usage Patterns
Example — Recommended
An atomic subsystem is used to split either side of the Switch block without using an action
subsystem.
B-13
B Usage Patterns
B-14
Usage Patterns
If a function can be achieved by using the action subsystem, then layering using the action subsystem
is not performed.
B-15
B Usage Patterns
In the Not Recommended example, when the lowest level Unit Delay block on the third level is
initialized, the conditional subsystem initialization is first executed one time on the upper first level,
and then again on the second level for a total of two times of initial value settings. To prevent the
generation of unnecessary code, it is recommended that listing not be made in conditional
subsystems that reside in levels where the state variable does not exist.
This is based on the concept that the model complexity is reduced by dropping to a level. The purpose
of the rule is to avoid the execution of unnecessary initializations.
For bifurcation of systems where the bifurcation condition nest has a deep structure, split by using
function conversions to decrease the code bifurcation nesting. Functions before and after the Switch
block are divided into respective subsystems, and function settings are applied to the atomic
subsystem + function. Be aware, it is possible that this may result in unintentional implementation
and unnecessary RAM requirements.
Not reviewing the error information returned by the functions can result in unintended behavior.
Example — Recommended
Error information is incorporated into the model structure, allowing the user to review and respond
to the errors.
B-16
Usage Patterns
[condition]
[condition1 ...
&& condition2 ...
&& condition3]
[condition1 ...
|| condition2 ...
|| condition3]
B-17
B Usage Patterns
action;
action1; ...
action2; ...
action3; ...
B-18
Usage Patterns
action1a;
action1b;
action2;
action3;
if (condition){
action;
}
if (condition) {
action1;
}
else {
action2;
}
B-19
B Usage Patterns
if (condition1) {
action1;
}
else if (condition2) {
action2;
}
else if (condition3) {
action3;
}
else {
action4;
}
Cascade of if construct.
if (condition1) {
action1;
if (condition2) {
action2;
if (condition3) {
action3;
}
}
}
selection = u1;
switch (selection) {
case 1:
y1 = 1;
break;
case 2:
y1 = 2;
break;
case 3:
y1 = 4;
break;
default:
y1 = 8;
}
B-20
Usage Patterns
c1 = u1;
c2 = u2;
c3 = u3;
if (c1 && ! c2 && ! c3) {
y1 = 1;
}
elseif (! c1 && c2 && ! c3) {
y1 = 2;
}
elseif (! c1 && ! c2 && c3) {
y1 = 4;
}
else {
y1 = 8;
}
for ( index = 0;
index < number_of_loops;
index++ )
{
action;
}
While loop construct
while ( condition )
{
action;
}
do
{
action;
}
while ( condition )
B-21
B Usage Patterns
(condition)
Up to three conditions, short form
(condition1 ...
&& condition2 ...
&& condition3)
(condition1 ...
|| condition2 ...
|| condition3)
action;
Two or more transition actions, multiline form
action1;
action2;
action3;
B-22
Usage Patterns
Example — Recommended
The constraint goal is set to three levels, but Level_4_a and Level_4_b have more than three levels
B-23
B Usage Patterns
B-24
Usage Patterns
• Transfer functions
• Integrators
• Table look-ups
• Complex equations
• If, elseif, else logic
B-25
C
Glossary
Atomic Subsystem
A subsystem block that executes the structural subsystem as a single unit. Conditional subsystems,
Stateflow Chart, and MATLAB Function blocks are considered atomic subsystems.
Basic Blocks
Built-in blocks in the standard Simulink library. Blocks with undefined internal processing, such as
subsystems, are not considered basic blocks
• Inport
• Outport
• Ground
• Terminator
• Constant
• Scope
• Saturation
• Unit Delay
• Delay
• Discrete-Time Integrator
• Switch
• Gain
• Product
• Relational Operator
• Logical Operator
Block
• Subsystems
• Models
• Charts (unless otherwise stated).
• Basic blocks
• Structural subsystems
C Usage Patterns
Conditional Subsystem
Delay Block
Two meanings:
1 The previous value reference block that is placed in the loop route to specify the execution order
in an algebraic loop (circular reference). Uses Unit Delay and Memory blocks.
(As of R2021b and later) The Delay block can also be used
2 A block that retains past values. Uses Unit Delay, Memory, Delay, and Tapped Delay blocks.
Calculation Block
Blocks whose block type is "sum" that carry out addition and subtraction operations. Includes Add,
Subtract, Sum, Sum of Elements blocks.
Flow Chart
The part of a model that describes the action for the transition condition by using transition
conditions and condition actions. The start point is the default transition line or internal transition
line. The end point is the connective junction. Does not include states that are between the start and
end points. Graphical functions and the inside of states can be modeled as flow charts.
Machine Level
Blocks whose block type is "product" that carry out division and multiplication operations. Includes
Product, Divide, and Product of Elements blocks.
Parameters
C-2
Usage Patterns
When modifications have not been made, this term refers to constants that are defined in the base
workspace and/or model workspace.
The names of Inport and Outport blocks are placed in a subsystem by default. Names of Stateflow
input and output data are displayed by default.
State
Stateflow Block
Subsystem
Even when the block type is "subsystem", blocks that describe the inside (other than Simulink) of a
model, such as Chart, MATLAB Function blocks, are not included. The Model block also is not
included.
C-3