Main Content

jc_0644: Type setting

Since R2020a

Guideline Publication

Control Algorithm Modeling Guidelines - Using MATLAB®, Simulink®, and Stateflow®

Sub ID Recommendations

  • NA-MAAB — No recommendations

  • JMAAB — a

MATLAB Versions

All

Rule

Sub ID a

The data type shall not be set by using a block or Stateflow data when the data type is set by a data object.

Exceptions

  • Inside a reusable function

  • Data Type Conversion block

  • Data types set by using fixdt

  • Boolean or double types

Custom Parameter

Not Applicable

Example — Correct

Type is set on the data object.

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.

  • A block with a specific type set by default.

    For example, Output data type is set to boolean by default. It is generally expected that the result of a logical operation boolean, eliminating the need to adjust inheritance settings. Given that the expected type is preconfigured in blocks set by default in this manner, readability and maintainability are not compromised.

Example — Correct

Type is set for the data object but not the block.

Example — Incorrect

Type is set for both the data object and the block.

Verification

Model Advisor check: Check type setting by data objects (Simulink Check)

Last Changed

R2024b

Version History

Introduced in R2020a