Simulink Mab Guidelines
Simulink Mab Guidelines
R2020b
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-62
Stateflow
4
Stateflow Blocks / Data / Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
v
Conditional Transition / Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-82
Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-168
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
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-13
Test for Information From Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-17
Flow Chart Patterns for Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-18
Flow Chart Patterns for Condition Actions . . . . . . . . . . . . . . . . . . . . . . . B-19
Flow Chart Patterns for If, Elseif, Else Constructs . . . . . . . . . . . . . . . . . B-20
Flow Chart Patterns for Case Constructs . . . . . . . . . . . . . . . . . . . . . . . . B-21
Flow Chart Patterns for Loop Constructs . . . . . . . . . . . . . . . . . . . . . . . . B-23
State Machine Patterns for Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . B-24
State Machine Patterns for Transition Actions . . . . . . . . . . . . . . . . . . . . B-24
jc_0321Limiting State Layering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-25
Number of States per Stateflow Container . . . . . . . . . . . . . . . . . . . . . . . B-26
Function Call from Stateflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-26
Function Types Available in Stateflow . . . . . . . . . . . . . . . . . . . . . . . . . . B-27
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
Modeling Guidelines and Model Advisor Checks for MAB and JMAAB
This table identifies MathWorks Advisor Board (MAB) guidelines, the corresponding Japan
MathWorks Automotive Advisor Board (JMAAB) guidelines, and Model Advisor check that you can use
to verify compliance with these guidelines. Additional information in the tables includes:
• MAB Modeling Guideline — Links to the MathWorks Advisory Board (MAB) guideline.
• Corresponding JMAAB Modeling Guideline — Identifies the JMAAB modelling guideline that
corresponds to the MAB guideline. To review the guideline, see Control Algorithm Modeling
Guidelines Using MATLAB, Simulink, and Stateflow on the MathWorks website.
• Model Advisor Check — Provides links to the Model Advisor check that is used to verify
compliance to the modeling guideline.
When applicable, this column clarifies why a guideline does not have a corresponding check:
• 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.
1-6
Model Advisor Checks for MAB Guidelines
1-7
1 Introduction
1-8
Model Advisor Checks for MAB Guidelines
1-9
1 Introduction
1-10
Model Advisor Checks for MAB Guidelines
1-11
1 Introduction
1-12
Model Advisor Checks for MAB Guidelines
1-13
1 Introduction
1-14
Model Advisor Checks for MAB Guidelines
1-15
1 Introduction
See Also
1-16
2
Naming Conventions
General Conventions
2-2
ar_0001: Usable characters for file names
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)
Example — Incorrect
001_JMAABModel.slx
Sub ID c
2-3
2 Naming Conventions
Custom Parameter
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
Sub ID g
File (extension)
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:
2-4
ar_0001: Usable characters for file names
• 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
• JMAAB guideline ar_0001, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Introduced in R2020a
2-5
2 Naming Conventions
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
Sub ID b
Not Applicable
Example — Incorrect
2-6
ar_0002: Usable characters for folder names
Sub ID c
Not Applicable
Example — Incorrect
Sub ID d
Not Applicable
Example — Incorrect
Sub ID e
Not Applicable
Example — Incorrect
Sub ID f
The folder name shall not consist solely of a single reserved MATLAB word.
Custom Parameter
Not Applicable
Example — Incorrect
2-7
2 Naming Conventions
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
R2020a
See Also
• JMAAB guideline ar_0002, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Introduced in R2020a
2-8
jc_0241: Length restriction for model file names
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
See Also
• JMAAB guideline jc_0241, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
2-9
2 Naming Conventions
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
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
See Also
• JMAAB guideline jc_0242, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
2-10
Content Conventions
Content Conventions
2-11
2 Naming Conventions
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
Sub ID b
2-12
jc_0201: Usable characters for subsystem names
Custom Parameter
Not Applicable
Example — Incorrect
Sub ID c
Not Applicable
Example — Incorrect
Sub ID d
Not Applicable
Example — Incorrect
Sub ID e
Not Applicable
Example — Incorrect
2-13
2 Naming Conventions
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)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0201, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Types of Subsystems”
Introduced in R2020a
2-14
jc_0231: Usable characters for block names
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
Example — Incorrect
2-15
2 Naming Conventions
Sub ID b
Not Applicable
Example — Incorrect
Sub ID c
Not Applicable
Example — Incorrect
2-16
jc_0231: Usable characters for block names
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
Example — Incorrect
2-17
2 Naming Conventions
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
• JMAAB guideline jc_0231, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Introduced in R2020a
2-18
jc_0211: Usable characters for Inport blocks and Outport block
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
Sub ID b
[Inport] and [Outport] block names shall not use numbers at the beginning.
2-19
2 Naming Conventions
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
Sub ID f
[Inport] and [Outport] block names shall not consist solely of a single reserved MATLAB word.
2-20
jc_0211: Usable characters for Inport blocks and Outport block
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
• JMAAB guideline jc_0211, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Introduced in R2020a
2-21
2 Naming Conventions
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of subsystem names” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0243, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Model Configuration Parameters”
• “Types of Subsystems”
Introduced in R2020a
2-22
jc_0247: Length restriction for block names
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
See Also
• JMAAB guideline jc_0247, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
2-23
2 Naming Conventions
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
See Also
• JMAAB guideline jc_0244, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
2-24
jc_0222: Usable characters for signal and bus names
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
Sub ID d
Signal and bus names shall not use underscores at the end.
Custom Parameter
Not Applicable
2-25
2 Naming Conventions
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
See Also
• JMAAB guideline jc_0222, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
• “Signal Basics”
2-26
jc_0222: Usable characters for signal and bus names
Introduced in R2020a
2-27
2 Naming Conventions
Sub ID Recommendations
• NA-MAAB — d, e
• JMAAB — a, b, c, d, e, f
MATLAB Versions
All
Rule
Sub ID a
Line break, single-byte space, double-byte characters, and control characters shall not be used.
Custom Parameter
Not Applicable
Sub ID b
Not Applicable
Sub ID c
Not Applicable
Sub ID d
Not Applicable
Sub ID e
2-28
jc_0232: Usable characters for parameter names
Custom Parameter
Not Applicable
Sub ID f
The parameter name 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 ID 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 ID f:
• 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
R2020a
See Also
• JMAAB guideline jc_0232, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reserved Keywords” (Embedded Coder)
• “Reserved Identifiers and Code Replacement” (Embedded Coder)
Introduced in R2020a
2-29
2 Naming Conventions
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
2-30
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
• JMAAB guideline jc_0245, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Model Configuration Parameters”
• “Signal Basics”
• “Simulink Bus Signals”
Introduced in R2020a
2-31
2 Naming Conventions
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Rationale
Sub ID a:
Verification
Model Advisor check: “Check length of parameter names” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0246, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
2-32
jc_0795: Usable characters for Stateflow data names
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.
Custom Parameter
Not Applicable
Rationale
Sub IDs a, b, c, d:
2-33
2 Naming Conventions
• 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
• JMAAB guideline jc_0795, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Add Stateflow Data” (Stateflow)
• “Set Data Properties” (Stateflow)
Introduced in R2020a
2-34
jc_0796: Length restriction for Stateflow data names
Sub ID Recommendations
• NA-MAAB — a, b, c, d
• JMAAB — a, b, c, d
MATLAB Versions
All
Rule
Sub ID a
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
See Also
• JMAAB guideline jc_0796, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Add Stateflow Data” (Stateflow)
• “Set Data Properties” (Stateflow)
Introduced in R2020a
2-35
2 Naming Conventions
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:
Verification
Model Advisor check: “Check duplication of Simulink data names” (Simulink Check)
Last Changed
R2020a
2-36
jc_0791: Duplicate data name definitions
See Also
• JMAAB guideline jc_0791, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Set Data Properties” (Stateflow)
• “Add Stateflow Data” (Stateflow)
• “Model Workspaces and Data Dictionaries”
Introduced in R2020a
2-37
2 Naming Conventions
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)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0792, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
2-38
jc_0792: Unused Data
Introduced in R2020a
2-39
2 Naming Conventions
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-40
jc_0700: Unused data in Stateflow block
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
• JMAAB guideline jc_0700, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Data, Events, and Messages” (Stateflow)
• “View Differences Between Stateflow Messages, Events, and Data” (Stateflow)
• “Manage Data, Events, and Messages in the Symbols Pane” (Stateflow)
Introduced in R2020a
2-41
2 Naming Conventions
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)
Last Changed
R2020a
See Also
• “Reserved Keywords” (Embedded Coder)
2-42
na_0019: Restricted variable names
Introduced in R2020a
2-43
3
Simulink
Configuration Parameters
3-2
jc_0011: Optimization parameters for Boolean data types
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
See Also
• JMAAB guideline jc_0011, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
Introduced in R2020a
3-3
3 Simulink
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-4
jc_0642: Integer rounding mode setting
Example — Incorrect
3-5
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check Signed Integer Division Rounding mode” (Simulink Check)
Last Changed
R2020a
See Also
• Sub ID a, see MISRA AC SLSF 008B
• JMAAB guideline jc_0642, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signed integer division rounds to”
Introduced in R2020a
3-6
jc_0806: Detecting incorrect calculation results
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
Rationale
Sub IDs a, b, c:
Verification
Model Advisor check: “Check diagnostic settings for incorrect calculation results” (Simulink Check)
3-7
3 Simulink
Last Changed
R2020a
See Also
• JMAAB guideline jc_0806, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-8
jc_0021: Model diagnostic settings
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
• Algebraic loop
• Minimize algebraic loop
• Multitask rate transition
• 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:
Verification
Model Advisor check “Check model diagnostic parameters” (Simulink Check)
3-9
3 Simulink
Last Changed
R2020a
Introduced in R2020a
3-10
Diagram Appearance
Diagram Appearance
3-11
3 Simulink
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.
Toolbar 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
Execution Context Deselect Execution Context.
Library Links Select Hide All Links.
Linearization Indicators Select Linearization Indicators.
Ref. Model I/O Mismatch Deselect Ref. Model I/O Mismatch.
Ref. Model Version Deselect Ref. Model Version.
Sample Time Colors Deselect Color.
Execution Order Deselect Execution Order.
3-12
na_0004: Simulink model appearance settings
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.
Drop shadow Deselect Shadow.
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.
Storage Class Deselect Storage Class.
Log & Testpoint Select. Log & Testpoint.
Viewers Select Viewers.
Nonscalar Signals Select Nonscalar Signals.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for Simulink diagrams using nonstandard display attributes” (Simulink
Check)
Last Changed
R2020a
See Also
• JMAAB guideline: na_0004, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• MISRA AC SLSF 023A
• “Mapping from Simulink Editor to the Simulink Toolstrip”
Introduced in R2020a
3-13
3 Simulink
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
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.
3-14
db_0043: Model font and font size
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
See Also
• JMAAB guideline db_0043, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-15
3 Simulink
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-16
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
• JMAAB guideline jm_0002, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Format a Model”
Introduced in R2020a
3-17
3 Simulink
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
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.
3-18
db_0142: Position of block names
Verification
Model Advisor check: “Check whether block names appear below blocks” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0142, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-19
3 Simulink
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Block names shall be hidden for blocks that meet the following criteria:
For blocks that do not meet the criteria, their name shall be displayed.
Custom Parameter
3-20
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
• JMAAB guideline jc_0061, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• MISRA AC SLSF 026A
Introduced in R2020a
3-21
3 Simulink
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
Rationale
Sub ID a:
3-22
db_0140: Display of block parameters
Verification
Model Advisor check: “Check for nondefault block attributes” (Simulink Check)
Last Changed
R2020a
See Also
• MISRA AC SLSF 026E
• JMAAB guideline db_0140, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Set Block Annotation Properties”
Introduced in R2020a
3-23
3 Simulink
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
Example — Correct
Sub ID b
Custom Parameter
3-24
jc_0603: Model description
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
• JMAAB guideline jc_0603, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-25
3 Simulink
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
3-26
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
• JMAAB guideline jc_0604, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Common Block Properties”
• “Set Block Parameter Values”
Introduced in R2020a
3-27
3 Simulink
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
Sub ID b
The model shall not have subsystems or basic blocks that are not connected.
Custom Parameter
Not Applicable
3-28
db_0081: Unconnected signals and blocks
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
• JMAAB guideline db_0081, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Types of Subsystems”
Introduced in R2020a
3-29
3 Simulink
Sub ID Recommendations
• NA-MAAB — a1/a2, b, c, e
• JMAAB — a1/a2, b, c, d, e
MATLAB Versions
All
Rule
Sub ID a1
Vertical and horizontal signal lines shall not cross over one another.
Custom Parameter
Not Applicable
Sub ID a2
(R2014a and later) When vertical and horizontal signal lines must cross, Simulink editor preference
Line crossing style shall be set to Line hop.
Custom Parameter
Not Applicable
Example — Correct
Sub ID b
Not Applicable
3-30
db_0032: Signal line connections
Sub ID c
Not Applicable
Sub ID d
Signal lines shall not split into more than two sub lines at a single branching point.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
Sub ID e
Signal lines shall be resized vertically or horizontally as required for the model layout.
Custom Parameter
Not Applicable
Rationale
Sub IDs a1, c:
• Difficult to understand the relationships between blocks when signal lines cross.
Sub ID a2:
3-31
3 Simulink
• In R2014a and later, the difference between crossing and branching is clarified.
Sub ID b:
• Difficult to understand the relationships between blocks when signal lines overlap.
Sub ID d:
Sub ID e:
Verification
Model Advisor check: “Check signal line connections” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0032, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
Introduced in R2020a
3-32
db_0141: Signal flow in Simulink models
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b, c
MATLAB Versions
All
Rule
Sub ID a
Exception
Custom Parameter
Not Applicable
Example — Correct
3-33
3 Simulink
Example — Incorrect
Sub ID b
Not Applicable
3-34
db_0141: Signal flow in Simulink models
Example — Correct
Example — Incorrect
Sub ID c
Not Applicable
3-35
3 Simulink
Example — Correct
Example — Incorrect
Rationale
Sub IDs a, b, c:
3-36
db_0141: Signal flow in Simulink models
Verification
Model Advisor check: “Check signal flow in model Check position of signal labels” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0141, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Types of Subsystems”
Introduced in R2020a
3-37
3 Simulink
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Exception
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.
Example — Incorrect
3-38
jc_0110: Direction of block
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
See Also
• JMAAB guideline jc_0110, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-39
3 Simulink
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
Example — Correct
3-40
jc_0171: Clarification of connections between structural subsystems
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
Example — Correct
3-41
3 Simulink
Example — Incorrect
Signals that are not used in the subsystem are connected to avoid crossing of signal lines.
Rationale
Sub ID a:
Sub ID b:
Verification
Model Advisor check: “Check connections between structural subsystems” (Simulink Check)
3-42
jc_0171: Clarification of connections between structural subsystems
Last Changed
R2020a
See Also
• JMAAB guideline jc_0171, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Types of Subsystems”
Introduced in R2020a
3-43
3 Simulink
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.
Custom Parameter
Not Applicable
Example — Correct
Names of model elements that connect directly to signal lines are consistent.
3-44
jc_0602: Consistency in model element names
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
• JMAAB guideline jc_0602, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Manage Signal Lines”
• “Types of Subsystems”
Introduced in R2020a
3-45
3 Simulink
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
Example — Incorrect
3-46
jc_0281: Trigger signal names
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-47
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-48
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-49
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-50
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-51
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
• JMAAB guideline jc_0281, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Use Events to Execute Charts” (Stateflow)
• “Types of Subsystems”
Introduced in R2020a
3-52
db_0143: Usable block types in model hierarchy
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
• Terminator
• From
• Goto
• Merge
• Unit Delay
3-53
3 Simulink
• Rate Transition
• Data Type Conversion
• Data Store Memory
• If
• Switch Case
• Function-Call Generator
• Function-Call Split
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
See Also
• JMAAB guideline db_0143, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-54
db_0144: Use of subsystems
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-55
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:
• 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
3-56
db_0144: Use of subsystems
See Also
• JMAAB guideline db_0144, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Types of Subsystems”
• Subsystem, Atomic Subsystem, CodeReuse Subsystem
Introduced in R2020a
3-57
3 Simulink
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.
Example — Incorrect
Delay block resides in a subsystem that is nested within the hierarchy which describes the feedback
loop.
3-58
jc_0653: Delay block layout in feedback loops
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for avoiding algebraic loops between subsystems” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0653, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-59
3 Simulink
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
Verification
Model Advisor check: “Check for prohibited sink blocks” (Simulink Check)
Last Changed
R2020a
3-60
hd_0001: Prohibited Simulink sinks
See Also
• “Viewers and Generators Manager”
Introduced in R2020a
3-61
3 Simulink
Signal
3-62
na_0010: Usage of vector and bus signals
Sub ID Recommendations
• NA-MAAB — a, b, c, d
• 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
Rationale
Sub IDs a, b, c, d:
• Prevents issues that are caused by combining vector and bus signals.
3-63
3 Simulink
Verification
Model Advisor check: “Check usage of vector and bus signals” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline na_0010, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Signal Types”
• “Data Types for Bus Signals”
• “Bus-Capable Blocks”
Introduced in R2020a
3-64
jc_0008: Definition of signal names
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-65
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 signal line labels” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0008, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Types of Subsystems”
Introduced in R2020a
3-66
jc_0009: Signal name propagation
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a, b
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-67
3 Simulink
Example — Incorrect
Show propagated signals is not selected, therefore signal names are not displayed.
3-68
jc_0009: Signal name propagation
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.
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-69
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-70
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-71
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-72
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.
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check for propagated signal labels” (Simulink Check)
3-73
3 Simulink
Last Changed
R2020a
See Also
• JMAAB guideline jc_0009, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
• “Types of Subsystems”
Introduced in R2020a
3-74
db_0097: Position of labels for signals and buses
Sub ID Recommendations
• NA-MAAB — a, b, c
• JMAAB — a, b,c
MATLAB Versions
All
Rule
Sub ID a
Signal line labels and bus labels shall not overlap other labels, signal lines, or blocks.
Custom Parameter
Not Applicable
Example — Correct
Signal line labels and bus labels do not overlap other labels, signal lines, or blocks.
Example — Incorrect
Signal line labels and bus labels overlap other labels, signal lines, or blocks.
3-75
3 Simulink
Sub ID b
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.
Sub ID c
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.
3-76
db_0097: Position of labels for signals and buses
Example — Incorrect
Signal line labels and bus labels are positioned at the destination of the signal line connection.
Rationale
Sub ID a:
• Adherence to this rule prevents confusion with corresponding names, signal lines, and buses,
which improves readability of the model.
Sub ID b, c:
• Consistent label position prevents confusion with corresponding labels, signal lines, and buses,
which improves the readability of the model.
Verification
Model Advisor check: “Check signal flow in model Check position of signal labels” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0097, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
3-77
3 Simulink
• “Signal Lines”
• “Simulink Bus Signals”
Introduced in R2020a
3-78
na_0008: Display of labels on signals
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:
• Outport
• Goto
• Data Store Write
• Bus Creator
• Mux
• Subsystem
3-79
3 Simulink
• 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”
• “Types of Subsystems”
Introduced in R2020a
3-80
na_0009: Entry versus propagation of signal labels
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
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.
3-81
3 Simulink
Verification
Model Advisor check: “Check for propagated signal labels” (Simulink Check)
Last Changed
R2020a
See Also
• “Signal Basics”
• “Manage Signal Lines”
• “Signal Label Propagation”
• “Types of Subsystems”
Introduced in R2020a
3-82
db_0110: Block parameters
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)
Last Changed
R2020a
3-83
3 Simulink
See Also
• JMAAB guideline db_0110, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-84
db_0112: Usage of index
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
Example — Incorrect
3-85
3 Simulink
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-86
db_0112: Usage of index
Rationale
Sub IDs a1, a2
Verification
Model Advisor check: “Check Indexing Mode” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0112, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• Index Vector
Introduced in R2020a
3-87
3 Simulink
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
Rationale
Sub ID a:
• A literal constant in the model will propagate as a literal constant in the generated code, making
calibration impossible.
3-88
jc_0645: Parameter definition for calibration
Verification
Model Advisor check: “Check if tunable block parameters are defined as named constants” (Simulink
Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0645, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Set Block Parameter Values”
Introduced in R2020a
3-89
3 Simulink
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.
Verification
Model Advisor check: “Check for sample time setting” (Simulink Check)
Last Changed
R2020a
3-90
jc_0641: Sample time setting
See Also
• JMAAB guideline jc_0641, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “What Is Sample Time?”
• “Types of Subsystems”
• “Construct and Run a Stateflow Chart” (Stateflow)
Introduced in R2020a
3-91
3 Simulink
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
See Also
• JMAAB guideline jc_0643, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Specify Fixed-Point Data Types”
• “Specify Data Types Using Data Type Assistant”
3-92
jc_0643: Fixed-point setting
Introduced in R2020a
3-93
3 Simulink
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 dictionary when the data type is set
by a data object.
Exceptions
Custom Parameter
Not Applicable
Example — Correct
3-94
jc_0644: Type setting
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-95
3 Simulink
Double type is generally used in plant models and for Rapid Control Prototyping (RCP),
therefore it is not within scope of this rule. Embedded software uses double type in specific
situations. Use caution when configuring the settings on these blocks to minimize the use of
double type.
Verification
Model Advisor check: “Check type setting by data objects” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0644, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “About Data Types in Simulink”
• “Simulink Functions Overview”
Introduced in R2020a
3-96
Conditional Subsystem Relations
3-97
3 Simulink
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
3-98
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
• JMAAB guideline db_0146, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
3-99
3 Simulink
Introduced in R2020a
3-100
jc_0640: Initial value settings for Outport blocks in conditional subsystems
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-101
3 Simulink
Example — Incorrect
3-102
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-103
3 Simulink
Verification
Model Advisor check: “Check undefined initial output for conditional subsystems” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0640, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Types of Subsystems”
• “Conditionally Executed Subsystems and Models”
Introduced in R2020a
3-104
jc_0659: Usage restrictions of signal lines input to Merge blocks
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-105
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of Merge block” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0659, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Types of Subsystems”
• “Conditionally Executed Subsystems Overview”
Introduced in R2020a
3-106
na_0003: Usage of If blocks
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-107
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
• JMAAB guideline na_0003, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Loops and Conditional Statements”
Introduced in R2020a
3-108
jc_0656: Usage of Conditional Control blocks
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 :
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-109
3 Simulink
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
• JMAAB guideline jc_0656, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Conditionally Executed Subsystems Overview”
• “Set Block Parameters”
• “Select Subsystem Execution”
Introduced in R2020a
3-110
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
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-111
3 Simulink
3-112
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
Example — Incorrect
If block example
3-113
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-114
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
3-115
3 Simulink
Example — Incorrect
If block example
3-116
jc_0657: Retention of output value based on conditional control flow blocks and Merge blocks
3-117
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
See Also
• JMAAB guideline jc_0657, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-118
Operation Blocks
Operation Blocks
3-119
3 Simulink
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-120
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
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.
3-121
3 Simulink
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
• JMAAB guideline na_0002, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Basics”
Introduced in R2020a
3-122
jc_0121: Usage of add and subtraction blocks
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.
Custom Parameter
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-123
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
3-124
jc_0121: Usage of add and subtraction blocks
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.
Custom Parameter
Not Applicable
3-125
3 Simulink
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
3-126
jc_0121: Usage of add and subtraction blocks
See Also
• JMAAB guideline jc_0121, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-127
3 Simulink
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-128
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:
Verification
Model Advisor check: “Check operator order of Product blocks” (Simulink Check)
Last Changed
R2020a
3-129
3 Simulink
See Also
• JMAAB guideline jc_0610, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Multiply and Divide Inputs Using the Product Block”
Introduced in R2020a
3-130
jc_0611: Input sign for multiplication and division blocks
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
See Also
• JMAAB guideline jc_0611, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Multiply and Divide Inputs Using the Product Block”
Introduced in R2020a
3-131
3 Simulink
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.
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
Last Changed
R2020a
See Also
• JMAAB guideline jc_0794, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• Multiply “Multiply and Divide Inputs Using the Product Block”
Introduced in R2020a
3-132
jc_0805: Numerical operation block inputs
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
Sub ID a2
Not Applicable
3-133
3 Simulink
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
Sub ID c1
3-134
jc_0805: Numerical operation block inputs
Custom Parameter
Not Applicable
Example — Correct
Simulation result
Example — Incorrect
Sub ID c2
Custom Parameter
Not Applicable
3-135
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-136
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-137
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-138
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-139
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-140
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-141
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-142
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-143
3 Simulink
Last Changed
R2020a
See Also
• JMAAB guideline jc_0805, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Specify Block Properties”
• “Control Signal Data Types”
Introduced in R2020a
3-144
jc_0622: Usage of Fcn blocks
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
See Also
• JMAAB guideline jc_0622, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Algebraic Loop Concepts”
Introduced in R2020a
3-145
3 Simulink
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-146
jc_0621: Usage of Logical Operator blocks
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
See Also
• JMAAB guideline jc_0621, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-147
3 Simulink
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
Example — Incorrect
Rationale
Sub ID a:
3-148
jc_0131: Usage of Relational Operator blocks
• 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
• JMAAB guideline jc_0131, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Relational and Logical Operators” (Embedded Coder)
Introduced in R2020a
3-149
3 Simulink
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-150
jc_0800: Comparing floating-point types in 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: “Comparing floating point types in Simulink” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0800, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Validate a Floating-Point Embedded Model”
Introduced in R2020a
3-151
3 Simulink
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
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.
Verification
Model Advisor check: “Check usage of Lookup Tables” (Simulink Check)
Last Changed
R2020a
3-152
jc_0626: Usage of Lookup Table blocks
See Also
• JMAAB guideline jc_0626, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Methods for Approximating Function Values”
Introduced in R2020a
3-153
3 Simulink
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
3-154
jc_0623: Usage of continuous-time Delay blocks and discrete-time Delay blocks
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of Memory and Unit Delay blocks” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0623, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Types of Subsystems”
• “Model a Continuous System”
• “Convert Signals Between Continuous Time and Discrete Time”
• “Discrete and Continuous Resettable Subsystems”
3-155
3 Simulink
Introduced in R2020a
3-156
jc_0624: Usage of Tapped Delay blocks/Delay blocks
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-157
3 Simulink
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-158
jc_0624: Usage of Tapped Delay blocks/Delay blocks
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
• JMAAB guideline jc_0624, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Signal Lines”
Introduced in R2020a
3-159
3 Simulink
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a, b
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-160
jc_0627: Usage of Discrete-Time Integrator blocks
Example — Incorrect
Sub ID b
When Discrete-Time Integrator block parameters Upper saturation limit and Lower saturation
limit are defined as Simulink.Parameter, parameter Data type shall be set to auto.
Custom Parameter
Not Applicable
3-161
3 Simulink
Example — Correct
3-162
jc_0627: Usage of Discrete-Time Integrator blocks
Example — Incorrect
Rationale
Sub ID a:
• Avoids block output overflow and prevents other computation blocks that use the output of this
block from producing unexpected results.
Sub ID b:
• Simulation errors occur when Data type is set to a value other than auto, single, or double.
Verification
Model Advisor check: “Check usage of Discrete-Time Integrator block” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0627, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
3-163
3 Simulink
• Simulink.Parameter
• “Simulink.Parameter Property Dialog Box”
Introduced in R2020a
3-164
jc_0628: Usage of Saturation blocks
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
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.
3-165
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check usage of the Saturation blocks” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0628, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-166
jc_0651: Implementing a type conversion
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Data Type Conversion block shall be used when changing the data type of the block output signal.
Custom Parameter
Not Applicable
Example — Correct
Data Type Conversion block is used to convert the data type of the Divide block output signal.
Example — Incorrect
Data Type Conversion block is not used to convert the data type of the [Divide] output signal.
3-167
3 Simulink
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 output data type of operation blocks” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0651, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-168
Other Blocks
Other Blocks
3-169
3 Simulink
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
Example — Incorrect
3-170
db_0042: Usage of Inport and Outport blocks
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-171
3 Simulink
Example — Incorrect
Sub ID c
Not Applicable
3-172
db_0042: Usage of Inport and Outport blocks
Example — Correct
Example — Incorrect
Rationale
Sub IDs a, b, c:
Verification
Model Advisor check: “Check position of Inport and Outport blocks” (Simulink Check)
Last Changed
R2020a
3-173
3 Simulink
See Also
• JMAAB guideline db_0042, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-174
jc_0081: Inport and Outport block icon display
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-175
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
• JMAAB guideline jc_0081, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Set Block Parameter Values”
• “Signal Basics”
• “Simulink Bus Signals”
Introduced in R2020a
3-176
na_0011: Scope of Goto and From blocks
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Rationale
Sub ID a:
• When hierarchies of the Goto block and corresponding From block are different, the connection
relationships can be difficult to understand.
• Simulation errors can occur when hierarchies of the Goto block and corresponding From block are
different and a virtual subsystem changes to an Atomic subsystem.
Verification
Model Advisor check: “Check scope of From and Goto blocks” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline na_0011, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Block-Specific Parameters”
• “Types of Subsystems”
• “Simulink Subsystem Semantics”
3-177
3 Simulink
Introduced in R2020a
3-178
jc_0161: Definition of Data Store Memory blocks
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)
Last Changed
R2020a
3-179
3 Simulink
See Also
• JMAAB guideline jc_0161, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Data Store Basics”
Introduced in R2020a
3-180
jc_0141: Usage of the Switch blocks
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
See Also
• JMAAB guideline jc_0141, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-181
3 Simulink
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-182
jc_0650: Block input/output data type with switching function
Example — Incorrect
The data port and output port have different data types.
3-183
3 Simulink
Rationale
Sub ID a:
Verification
Model Advisor check: “Check input and output datatype for Switch blocks” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0650, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-184
jc_0630: Usage of Multiport Switch blocks
Sub ID Recommendations
• NA-MAAB — a, 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
Sub ID b
The input to the Multiport Switch control port shall be an unsigned integer.
Custom Parameter
Not Applicable
Sub ID c
When Multiport Switch block parameter Data port order is set to Specify indices, these block
parameters shall be set as follows:
Custom Parameter
Not Applicable
3-185
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-186
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
R2020a
See Also
• JMAAB guideline jc_0630, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
3-187
3 Simulink
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 subsystem or model
reference shall be the same.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
3-188
na_0020: Number of inputs to variant subsystems
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-189
3 Simulink
Rationale
Sub IDs a, b:
Verification
Model Advisor check: “Check for missing ports in Variant Subsystems” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline na_0020, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Types of Subsystems”
• “Model Reference Basics”
• “Create a Simple Variant Model”
Introduced in R2020a
3-190
na_0036: Default variant
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-191
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
Rationale
Sub IDs a, b:
3-192
na_0036: Default variant
Verification
Model Advisor check: “Check use of default variants” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline na_0036, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Variant Subsystems”
• “Propagating Variant Conditions to Subsystems”
Introduced in R2020a
3-193
3 Simulink
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.
Example — Incorrect
The variant condition is set by a compound condition that is formed from multiple variables.
3-194
na_0037: Use of single variable for variant condition
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
• JMAAB guideline na_0037, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “What Are Variants and When to Use Them”
• “Introduction to Variant Controls”
Introduced in R2020a
3-195
4
Stateflow
4-2
db_0122: Stateflow and Simulink interface signals and parameters
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Chart block parameter Use Strong Data Typing with Simulink I/O shall be selected so that strong
data typing between a Stateflow chart and Simulink is permitted.
Note Use Strong Data Typing with Simulink I/O is available only whenChart block property
Action Language is set to C.
Custom Parameter
Not Applicable
Example — Correct
Parameter Use Strong Data Typing with Simulink I/O is selected, so the input and output is set to
uint8 type.
Example — Incorrect
Parameter Use Strong Data Typing with Simulink I/O is not selected, so the input and output is
set to double type.
4-3
4 Stateflow
Rationale
Sub ID a:
• When parameter Use Strong Data Typing with Simulink I/O is not selected, the Simulink
signal data type that can input and output to a Stateflow Chart is set to double type:
• As a result, type conversion is required prior to input and after output, which increases the
number of blocks and decreases readability.
• However, input data of any type in a Stateflow Chart can connect directly with that signal.
When these two signals have different data types, an implicit data type conversion occurs. By
selecting the parameter, the implicit data type conversion does not take place and a data type
inconsistency error is generated. This prevents misunderstandings due to differences in data
type, thus improving readability.
Verification
Model Advisor check: “Check for Strong Data Typing with Simulink I/O” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0122, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• Chart
• “Strong Data Typing with Simulink Inputs and Outputs” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Introduced in R2020a
4-4
db_0123: Stateflow port names
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
See Also
• “Set Data Properties” (Stateflow)
• “Reusable Components in Charts” (Stateflow)
Introduced in R2020a
4-5
4 Stateflow
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-6
db_0125: Stateflow local data
Example — Correct
Example — Incorrect
4-7
4 Stateflow
Sub ID b
Data objects shall not be defined with Scope set to Constant at the machine level.
Custom Parameter
Not Applicable
4-8
db_0125: Stateflow local data
Example — Correct
Example — Incorrect
4-9
4 Stateflow
Sub ID c
Data objects shall not be defined with Scope set to Parameter at the machine level.
Custom Parameter
Not Applicable
4-10
db_0125: Stateflow local data
Example — Correct
Example — Incorrect
4-11
4 Stateflow
Sub ID d
A Stateflow block with parent-child relationships shall not include local data with the same name.
Custom Parameter
Not Applicable
Example — Correct
4-12
db_0125: Stateflow local data
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:
4-13
4 Stateflow
• Adherence to the rules prevent the definition from disappearing when copying a Stateflow block to
another model.
Sub ID d:
• When a Stateflow block with parent-child relationships includes local data with the same name,
readability decreases due to lack of clarity with regard to the influence of the local data.
Verification
Model Advisor check: “Check definition of Stateflow data” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0125, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Stateflow Data Properties” (Stateflow)
• “Use the Model Explorer with Stateflow Objects” (Stateflow)
• “State Hierarchy” (Stateflow)
Introduced in R2020a
4-14
db_0126: Defining Stateflow events
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-15
4 Stateflow
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check definition of Stateflow events” (Simulink Check)
4-16
db_0126: Defining Stateflow events
Last Changed
R2020a
See Also
• JMAAB guideline db_0126, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Synchronize Model Components by Broadcasting Events” (Stateflow)
• “Use the Model Explorer with Stateflow Objects” (Stateflow)
Introduced in R2020a
4-17
4 Stateflow
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
Example — Correct
4-18
jc_0701: Usable number for first index
Example — Incorrect
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
• JMAAB guideline jc_0701, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
• “Set Data Properties” (Stateflow)
Introduced in R2020a
4-22
jc_0712: Execution timing for default transition path
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
propertyExecute (Enter) Chart at Initialization is selected.
Verification
Model Advisor check: “Check execution timing for default transition path” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0712, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
4-23
4 Stateflow
Introduced in R2020a
4-24
jc_0722: Local data definition in parallel states
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
• JMAAB guideline jc_0722, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “States” (Stateflow)
• “Parallel and Exclusive States” (Stateflow)
Introduced in R2020a
4-28
Stateflow Diagram
Stateflow Diagram
4-29
4 Stateflow
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
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:
Verification
Model Advisor check: “Check for unconnected objects in Stateflow Charts” (Simulink Check)
Last Changed
R2020a
4-31
4 Stateflow
See Also
• JMAAB guideline jc_0797, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “Exclusive (OR) State Decomposition” (Stateflow)
• “Transition Between Exclusive States” (Stateflow)
• “Transition Between Operating Modes” (Stateflow)
• “Represent Multiple Paths by Using Connective Junctions” (Stateflow)
• “Transitions to and from Junctions” (Stateflow)
Introduced in R2020a
4-32
db_0137: States in state machines
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)
Rationale
Sub ID a:
4-33
4 Stateflow
Verification
Model Advisor check: “Check for state in state machines” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0137, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “States” (Stateflow)
• “State Decomposition” (Stateflow)
Introduced in R2020a
4-34
jc_0721: Usage of parallel states
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
• JMAAB guideline jc_0721, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “States” (Stateflow)
• “Parallel and Exclusive States” (Stateflow)
• “State Hierarchy” (Stateflow)
Introduced in R2020a
4-38
db_0129: Stateflow transition appearance
Sub ID Recommendations
• NA-MAAB — a, b, c, d, e
• JMAAB — a, b, c, d, e
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-39
4 Stateflow
Example — Incorrect
Sub ID b
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-40
db_0129: Stateflow transition appearance
Sub ID c
Not Applicable
Example — Correct
Example — Incorrect
Sub ID d
Not Applicable
4-41
4 Stateflow
Example — Correct
Example — Incorrect
Sub ID e
Not Applicable
4-42
db_0129: Stateflow transition appearance
Example — Correct
Example — Incorrect
Rationale
Sub ID a:
• Difficult to understand the relationship between states when transition lines cross.
Sub ID b:
• Difficult to understand the relationship between states when transition lines overlap.
Sub ID c:
• Difficult to understand the relationship between states when transition lines cross over states.
Sub ID d:
Sub ID e:
• Transitions can be difficult to understand when unnecessary connective junctions are used.
Verification
Model Advisor check: “Check for Stateflow transition appearance” (Simulink Check)
4-43
4 Stateflow
Last Changed
R2020a
See Also
• JMAAB guideline db_0129, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “Transition Between Operating Modes” (Stateflow)
Introduced in R2020a
4-44
jc_0531: Default transition
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-45
4 Stateflow
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-46
jc_0531: Default transition
Example — Correct
Example — Incorrect
4-47
4 Stateflow
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-48
jc_0531: Default transition
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-49
4 Stateflow
Sub ID f
Default transitions shall not extend beyond the boundaries of the state.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-50
jc_0531: Default transition
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-51
4 Stateflow
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-52
jc_0531: Default transition
Verification
Model Advisor check: “Check default transition placement in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0531, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “State Decomposition” (Stateflow)
• “Transitions” (Stateflow)
• “How Stateflow Objects Interact During Execution” (Stateflow)
Introduced in R2020a
4-53
4 Stateflow
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-54
jc_0723: Prohibited direct transition from external state to child state
Example — Incorrect
Direct transition from an external child state to a child state in a different state.
4-55
4 Stateflow
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)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0723, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
Introduced in R2020a
4-56
jc_0751: Backtracking prevention in state transition
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
4-57
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
• JMAAB guideline jc_0751, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “Evaluate Transitions” (Stateflow)
• “Transitions to and from Junctions” (Stateflow)
Introduced in R2020a
4-58
jc_0760: Starting point of internal transition
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-59
4 Stateflow
Example — Incorrect
The inner transition line does not begin at the left edge of the state.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check starting point of internal transition in Stateflow” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0760, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Inner Transitions” (Stateflow)
Introduced in R2020a
4-60
jc_0763: Usage of multiple internal transitions
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
4-61
4 Stateflow
Example — Incorrect
4-62
jc_0763: Usage of multiple internal transitions
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-63
4 Stateflow
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 a1:
• 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
• JMAAB guideline jc_0763, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Hierarchy of Stateflow Objects” (Stateflow)
• “Adding the Transitions” (Stateflow)
• “Drawing the Transitions Between States” (Stateflow)
• “Types of Chart Execution” (Stateflow)
Introduced in R2020a
4-64
jc_0762: Prohibition of state action and flow chart combination
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-65
4 Stateflow
Example — Incorrect
The state includes state actions en and du and also a flow chart.
4-66
jc_0762: Prohibition of state action and flow chart combination
Rationale
Sub ID a:
Verification
Model Advisor check: “Check prohibited combination of state action and flow chart” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0762, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Flow Charts in Stateflow” (Stateflow)
• “State Action Types” (Stateflow)
4-67
4 Stateflow
Introduced in R2020a
4-68
db_0132: Transitions in flow charts
Sub ID Recommendations
• NA-MAAB — a, b
• JMAAB — a, b
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
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.
4-69
4 Stateflow
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:
Sub ID b:
4-70
db_0132: Transitions in flow charts
Verification
Model Advisor check: “Check transitions in Stateflow Flow charts” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0132, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “Transition Between Operating Modes” (Stateflow)
• “Transition Action Types” (Stateflow)
Introduced in R2020a
4-71
4 Stateflow
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
Example — Correct
4-72
jc_0773: Unconditional transition of a flow chart
Example — Incorrect
Sub ID b
The execution order for unconditional transitions shall be set to the last value.
Custom Parameter
Not Applicable
Example — Correct
4-73
4 Stateflow
Example — Incorrect
The execution order for unconditional transitions is not the last value.
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
• JMAAB guideline jc_0773, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
4-74
jc_0773: Unconditional transition of a flow chart
• “Transitions” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
Introduced in R2020a
4-75
4 Stateflow
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
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
• JMAAB guideline: jc_0775, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Evaluate Transitions” (Stateflow)
• “Represent Multiple Paths by Using Connective Junctions” (Stateflow)
Introduced in R2020a
4-78
jc_0738: Usage of Stateflow comments
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
Example — Incorrect
4-79
4 Stateflow
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:
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)
4-80
jc_0738: Usage of Stateflow comments
Last Changed
R2020a
See Also
• JMAAB guideline jc_0738, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
• “Modify the Action Language for a Chart” (Stateflow)
Introduced in R2020a
4-81
4 Stateflow
4-82
jc_0790: Action language of Chart block
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-83
4 Stateflow
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
• JMAAB guideline jc_0790, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Modify the Action Language for a Chart” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Introduced in R2020a
4-84
jc_0702: Use of named Stateflow parameters and constants
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
• JMAAB guideline jc_0702, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Rules for Naming Stateflow Objects” (Stateflow)
Introduced in R2020a
4-86
jm_0011: Pointers in Stateflow
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-87
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for pointers in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jm_0011, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
4-88
jm_0011: Pointers in Stateflow
Introduced in R2020a
4-89
4 Stateflow
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-90
jc_0491: Reuse of Stateflow data
Example — Incorrect
4-91
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-92
jc_0491: Reuse of Stateflow data
Last Changed
R2020a
See Also
• JMAAB guideline jc_0491, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Construct and Run a Stateflow Chart” (Stateflow)
Introduced in R2020a
4-93
4 Stateflow
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a1/a2/a3
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
Example — Incorrect
4-94
jm_0012: Usage restrictions of events and broadcasting events
Sub ID a2
The send syntax send(event_name, state_name) shall be used to broadcast Stateflow events.
Custom Parameter
Not Applicable
Example — Correct
4-95
4 Stateflow
Example — Incorrect
The state that receives the broadcast has not been defined in the send syntax.
4-96
jm_0012: Usage restrictions of events and broadcasting events
Sub ID a3
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-97
4 Stateflow
Rationale
Sub ID a1:
• 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 and broadcasting events in Stateflow charts”
(Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jm_0012, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Events” (Stateflow)
• “Use Events to Execute Charts” (Stateflow)
4-98
jm_0012: Usage restrictions of events and broadcasting events
Introduced in R2020a
4-99
4 Stateflow
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-100
jc_0733: Order of state action types
Example — Correct
Example — Incorrect
4-101
4 Stateflow
Sub ID b
entry (en)
during (du)
exit (ex)
Custom Parameter
Not Applicable
4-102
jc_0733: Order of state action types
Example — Correct
Example — Incorrect
4-103
4 Stateflow
Rationale
Sub ID a:
Verification
Model Advisor check: “Check order of state action types” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0733, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “State Action Types” (Stateflow)
• “Enter a Chart” (Stateflow)
• “During Actions” (Stateflow)
• “Exit a State” (Stateflow)
Introduced in R2020a
4-104
jc_0734: Number of state action types
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
State action types shall not describe the same thing more than twice.
Custom Parameter
Not Applicable
Example — Correct
4-105
4 Stateflow
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
• JMAAB guideline jc_0734, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “State Action Types” (Stateflow)
Introduced in R2020a
4-106
jc_0740: Limitation on use of exit state action
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-107
4 Stateflow
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
• JMAAB guideline jc_0740, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “State Actions” (Stateflow)
• “Exit a State” (Stateflow)
Introduced in R2020a
4-108
jc_0741: Timing to update data used in state chart transition conditions
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Variables that are used in a state transition condition shall not use state action du to perform an
update.
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-109
4 Stateflow
Rationale
Sub ID a:
• 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
R2020a
See Also
• JMAAB guideline jc_0741, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “State Action Types” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
Introduced in R2020a
4-110
jc_0772: Execution order and transition conditions of transition lines
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-111
4 Stateflow
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
• JMAAB guideline jc_0772, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transitions” (Stateflow)
• “Conditions” (Stateflow)
• “Design Considerations for Defining Transitions Between States” (Stateflow)
• “Types of Chart Execution” (Stateflow)
• “Execution of a Stateflow Chart” (Stateflow)
Introduced in R2020a
4-112
jc_0753: Condition actions and transition actions in Stateflow
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-113
4 Stateflow
Sub ID a2
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
4-114
jc_0753: Condition actions and transition actions in Stateflow
Rationale
Sub ID a1:
Sub ID a2:
• 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
R2020a
See Also
• JMAAB guideline jc_0753, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Condition and Transition Actions” (Stateflow)
Introduced in R2020a
4-115
4 Stateflow
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
Example — Incorrect
4-116
jc_0711: Division in Stateflow
Sub ID a2
When division occurs in a Stateflow Chart, the process shall prevent division by zero.
Custom Parameter
Not Applicable
Example — Correct
4-117
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-118
jc_0711: Division in Stateflow
Last Changed
R2020a
See Also
• JMAAB guideline jc_0711, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Fixed-Point Operations in Stateflow Charts” (Stateflow)
Introduced in R2020a
4-119
4 Stateflow
Sub ID Recommendations
• NA-MAAB — a1/a2
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
4-120
db_0127: Limitation on MATLAB commands in Stateflow blocks
Example — Incorrect
Sub ID a2
When a MATLAB command is used in Stateflow blocks, it shall be accessed only by using MATLAB
Function block.
Custom Parameter
Not Applicable
Example — Correct
4-121
4 Stateflow
Example — Incorrect
Rationale
Sub ID a1:
• Not all MATLAB commands are supported for code generation. As a result, code may not be
generated for these unsupported MATLAB commands.
Sub ID a2:
• Not all MATLAB commands are supported for code generation. As a result, code may not be
generated for these unsupported MATLAB commands.
• Readability improves when C and MATLAB action languages are described separately.
4-122
db_0127: Limitation on MATLAB commands in Stateflow blocks
Verification
Model Advisor check: “Check for MATLAB expressions in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline db_0127, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• MATLAB Function
• “Stateflow Programmatic Interface” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Introduced in R2020a
4-123
4 Stateflow
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
• ==
• !=
• ~=
Custom Parameter
Not Applicable
Example — Correct
Example — Incorrect
4-124
jc_0481: Use of hard equality comparisons for floating point numbers in Stateflow
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
R2020a
See Also
• JMAAB guideline jc_0481, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Fixed-Point Data in Stateflow Charts” (Stateflow)
• “Relational Operations”
Introduced in R2020a
4-125
4 Stateflow
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-126
na_0001: Standard usage of Stateflow operators
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-127
4 Stateflow
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
4-128
na_0001: Standard usage of Stateflow operators
Example — Correct
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
4-129
4 Stateflow
See Also
• JMAAB guideline na_0001, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Modify the Action Language for a Chart” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Introduced in R2020a
4-130
jc_0655: Prohibition of logical value comparison in Stateflow
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
4-131
4 Stateflow
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check prohibited comparison operation of logical type signals” (Simulink
Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0655, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
4-132
jc_0655: Prohibition of logical value comparison in Stateflow
Introduced in R2020a
4-133
4 Stateflow
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.)
Rationale
Sub ID a:
4-134
jc_0451: Use of unary minus on unsigned integers
• 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
• JMAAB guideline jc_0451, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Data Types Supported by Simulink”
• “Unary Minus of Matrix Input”
Introduced in R2020a
4-135
4 Stateflow
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-136
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
Calculations are performed between unsigned integer type variables and signed integers.
4-137
4 Stateflow
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
• JMAAB guideline jc_0802, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Type Cast Operations” (Stateflow)
• “Differences Between MATLAB and C as Action Language Syntax” (Stateflow)
Introduced in R2020a
4-138
jc_0803: Passing values to library functions
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
Example — Incorrect
Sub ID a2
4-139
4 Stateflow
Custom Parameter
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
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
4-140
jc_0803: Passing values to library functions
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
Example — Correct
4-141
4 Stateflow
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 modelling 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
See Also
• JMAAB guideline jc_0803, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Extrinsic Functions”
• “Library Development” (Embedded Coder)
Introduced in R2020a
4-142
Label Description
Label Description
4-143
4 Stateflow
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
Example — Correct
Example — Incorrect
4-144
jc_0732: Distinction between state names, data names, and event names
Rationale
Sub ID a:
Verification
Model Advisor check: “Check uniqueness of Stateflow State and Data names” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0732, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
4-145
4 Stateflow
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
See Also
• JMAAB guideline jc_0730, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “States” (Stateflow)
• “Atomic Subcharts” (Stateflow)
Introduced in R2020a
4-146
jc_0731: State name format
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:
Verification
Model Advisor check: “Check usage of State names” (Simulink Check)
4-147
4 Stateflow
Last Changed
R2020a
See Also
• JMAAB guideline jc_0731, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “States” (Stateflow)
Introduced in R2020a
4-148
jc_0501: Format of entries in a State block
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-149
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
• JMAAB guideline jc_0501, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “State Action Types” (Stateflow)
Introduced in R2020a
4-150
jc_0736: Uniform indentations in Stateflow blocks
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.
Example — Incorrect
Executable statements do not have a single-byte space at the start of the line.
4-151
4 Stateflow
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-152
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:
Verification
Model Advisor check: “Check indentation of code in Stateflow states” (Simulink Check)
Last Changed
R2020a
4-153
4 Stateflow
See Also
• JMAAB guideline jc_0736, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Specify Transition Conditions” (Stateflow)
• “Transition Action Types” (Stateflow)
Introduced in R2020a
4-154
jc_0739: Describing text inside states
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Text inside a state shall not extend beyond the boundaries of the state
Custom Parameter
Not Applicable
Example — Incorrect
4-155
4 Stateflow
Rationale
Sub ID a:
• When the text inside a state extends beyond its boundaries, it can be difficult to determine which
state the text belongs.
Verification
Model Advisor check: “Check for usage of text inside states” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0739, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
Introduced in R2020a
4-156
jc_0770: Position of transition label
Sub ID Recommendations
• NA-MAAB — No recommendations
• JMAAB — a1/a2
MATLAB Versions
All
Rule
Sub ID a1
Not Applicable
Example — Correct
Example — Incorrect
The positioning of transition labels is inconsistent and do not correspond to the transition line.
4-157
4 Stateflow
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-158
jc_0770: Position of transition label
Example — Incorrect
The positioning of transition labels is inconsistent and do not correspond to the transition line.
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)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0770, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Transition Labels” (Stateflow)
• “Label Transitions” (Stateflow)
• “Move Transitions” (Stateflow)
Introduced in R2020a
4-159
4 Stateflow
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
Example — Incorrect
4-160
jc_0771: Comment position in transition labels
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
Example — Incorrect
4-161
4 Stateflow
Rationale
Sub IDs a1, a2:
Verification
Model Advisor check: “Check position of comments in transition labels” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0771, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Label Transitions” (Stateflow)
• “Add Descriptive Comments in a Chart” (Stateflow)
Introduced in R2020a
4-162
jc_0752: Condition action in transition label
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
Rationale
Sub ID a:
4-163
4 Stateflow
Verification
Model Advisor check: “Check usage of parentheses in Stateflow transitions” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0752, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Label Transitions” (Stateflow)
• “Condition Actions” (Stateflow)
Introduced in R2020a
4-164
jc_0774: Comments for through transition
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-165
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.
Rationale
Sub ID a:
Verification
Model Advisor check: “Check for comments in unconditional transitions” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline jc_0774, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Add Descriptive Comments in a Chart” (Stateflow)
• “Transitions” (Stateflow)
4-166
jc_0774: Comments for through transition
Introduced in R2020a
4-167
4 Stateflow
Miscellaneous
4-168
jc_0511: Return values from a graphical function
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-169
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
• JMAAB guideline jc_0511, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Flow Charts in Stateflow” (Stateflow)
• “Create Flow Charts by Using Pattern Wizard” (Stateflow)
4-170
jc_0511: Return values from a graphical function
Introduced in R2020a
4-171
4 Stateflow
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-172
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.
Last Changed
R2020a
See Also
• JMAAB guideline jc_0804, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Reuse Logic Patterns by Defining Graphical Functions” (Stateflow)
• “How Stateflow Objects Interact During Execution” (Stateflow)
Introduced in R2020a
4-173
4 Stateflow
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 in the Simulink Function block.
• 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-174
na_0042: Usage of Simulink functions
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
• JMAAB guideline na_0042, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Simulink Functions Overview”
• “Simulink functions: Simulink Function block, exported Stateflow graphical and MATLAB
functions”
Introduced in R2020a
4-175
4 Stateflow
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-176
na_0039: Limitation on Simulink functions in Chart blocks
Example — Incorrect
Rationale
Sub ID a:
Verification
Model Advisor check: “Check use of Simulink in Stateflow charts” (Simulink Check)
Last Changed
R2020a
See Also
• JMAAB guideline na_0039, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Simulink Functions Overview”
4-177
4 Stateflow
• “Simulink functions: Simulink Function block, exported Stateflow graphical and MATLAB
functions”
Introduced in R2020a
4-178
5
MATLAB
MATLAB Appearance
5-2
na_0025: MATLAB Function header
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
Rationale
Sub ID a:
5-3
5 MATLAB
Verification
Adherence to this modeling guideline cannot be verified by using a Model Advisor check.
Last Changed
R2020a
See Also
• “Implementing MATLAB Functions Using Blocks”
Introduced in R2020a
5-4
na_0018: Number of nested if/else and case statement
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 MATLAB Function metrics” (Simulink Check)
Last Changed
R2020a
See Also
• “Loops and Conditional Statements”
Introduced in R2020a
5-5
5 MATLAB
5-6
na_0024: Shared data in MATLAB functions
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-7
5 MATLAB
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
end
Rationale
Sub ID a:
5-8
na_0024: Shared data in MATLAB functions
• 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
• JMAAB guideline na_0024, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Implementing MATLAB Functions Using Blocks”
• “Signal Lines”
• “Resolve Signal Objects for Output Data”
Introduced in R2020a
5-9
5 MATLAB
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
Rationale
Sub ID a:
5-10
na_0031: Definition of default enumerated value
• 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
• JMAAB guideline na_0031, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Use Enumerated Data in Simulink Models”
• “Define Enumerated Data Types” (Stateflow)
• “Instantiate Enumerations”
Introduced in R2020a
5-11
5 MATLAB
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
See Also
• JMAAB guideline na_0034, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Implementing MATLAB Functions Using Blocks”
Introduced in R2020a
5-12
MATLAB Usage
MATLAB Usage
5-13
5 MATLAB
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 MATLAB Function metrics” (Simulink Check)
Last Changed
R2020a
See Also
• “Program a MATLAB Function in a Chart” (Stateflow)
• “Implementing MATLAB Functions Using Blocks”
Introduced in R2020a
5-14
na_0017: Number of called function levels
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)
Last Changed
R2020a
5-15
5 MATLAB
See Also
• “Implementing MATLAB Functions Using Blocks”
• “Program a MATLAB Function in a Chart” (Stateflow)
• “Exponents and Logarithms”
Introduced in R2020a
5-16
na_0021: Strings in MATLAB functions
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — a
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Incorrect
function y = fcn(u)
%#codegen
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:
• 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
5-17
5 MATLAB
Verification
Model Advisor check: “Check usage of character vector inside MATLAB Function block” (Simulink
Check)
Last Changed
R2020a
See Also
• JMAAB guideline na_0021, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “Implementing MATLAB Functions Using Blocks”
• “Program a MATLAB Function in a Chart” (Stateflow)
Introduced in R2020a
5-18
na_0022: Recommended patterns for Switch/Case statements
Sub ID Recommendations
• NA-MAAB — a
• JMAAB — Not supported
MATLAB Versions
All
Rule
Sub ID a
Not Applicable
Example — Correct
Example — Incorrect
5-19
5 MATLAB
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”
Introduced in R2020a
5-20
jc_0801: Prohibited use of the /* and */ comment symbols
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:
Not Applicable
Example — Incorrect
5-21
5 MATLAB
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
See Also
• JMAAB guideline jc_0801, which is available in Control Algorithm Modeling Guidelines Using
MATLAB, Simulink, and Stateflow on the MathWorks website.
• “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)
Introduced in R2020a
5-22
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 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 concepts 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
1 Set configuration parameter Tasking mode for periodic sample times to SingleTasking for
Simulink task setting.
2 In the Atomic Subsystem block parameter Sample time, enter the sampling period offset values.
A subsystem for which a sampling period can be specified is referred to as an atomic subsystem.
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 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 subsystem 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 operators, see “Supported Operations for Chart 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:
open_system('sf_custom')In
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 theses 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
B-5
B Usage Patterns
output_signal = 0;
for (i=0; i>input_vector_size; i++) {
output_signal = output_signal -
input_vector[i];
}
Example — Recommended
For a simple if, elseif, else structure, use the Switch block.
B-6
Usage Patterns
Using If and If Action Subsystem blocks for a simple if, elseif, else structure.
Example — Recommended
For a complex if, elseif, else structure, use If and If Action Subsystem blocks.
B-7
B Usage Patterns
B-8
Usage Patterns
Example — Recommended
By setting the fourth level as an if action subsystem, nesting is limited to a single level.
B-9
B 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-10
Usage Patterns
Use a description method that avoids layering of nesting in the Switch block.
B-11
B 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-12
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-13
B Usage Patterns
Example — Recommended
An atomic subsystem is used to split either side of the Switch block without using an action
subsystem.
B-14
Usage Patterns
B-15
B Usage Patterns
If a function can be achieved by using the action subsystem, then layering using the action subsystem
is not performed.
B-16
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-17
B Usage Patterns
[condition]
[condition1 ...
&& condition2 ...
&& condition3]
[condition1 ...
|| condition2 ...
|| condition3]
B-18
Usage Patterns
action;
action1; ...
action2; ...
action3; ...
B-19
B Usage Patterns
action1a;
action1b;
action2;
action3;
if (condition){
action;
}
if (condition) {
action1;
}
else {
action2;
}
B-20
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;
}
}
}
B-21
B Usage Patterns
selection = u1;
switch (selection) {
case 1:
y1 = 1;
break;
case 2:
y1 = 2;
break;
case 3:
y1 = 4;
break;
default:
y1 = 8;
}
B-22
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;
}
B-23
B Usage Patterns
do
{
action;
}
while ( condition )
(condition)
Up to three conditions, short form
(condition1 ...
&& condition2 ...
&& condition3)
(condition1 ...
|| condition2 ...
|| condition3)
B-24
Usage Patterns
action;
action1;
action2;
action3;
Example — Recommended
B-25
B Usage Patterns
The constraint goal is set to three levels, but Level_4_a and Level_4_b have more than three levels
B-26
Usage Patterns
• Transfer functions
• Integrators
• Table look-ups
• Complex equations
• If, elseif, else logic
B-27
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.
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 modelled 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 basic
projection) of a model, such as Chart, MATLAB Function blocks, are not included. The Model block
also is not included.
C-3