MATLAB Function Block Support

Simulink® Code Inspector™ supports a subset of MATLAB Function block’s language and features for code inspection. The code inspector verifies the use of the MATLAB Function block. For the supported language and features, some constraints may apply. Before code inspection, when you check the compatibility of your model with code inspection rules, the compatibility checker detects and reports violations of MATLAB Function block constraints. Simulink Code Inspector supports the following for code inspection:

MATLAB Function block featureWhat is supported
Data type
  • Built-in data types: boolean, int8, int16, int32, uint8, uint16, uint32, single, and double

  • Bus

  • Enumerated types inherited from Simulink.IntEnumType

Data dimension and complexity
  • Scalar, vector, and matrix data

  • Sampling mode of output signal set to Sample-based

  • Real data

Data scope
  • Input

  • Output

  • Parameter

  • Storage classes under the following conditions:

    • Type is set to Unstructured

    • Storage class is not reusable

  • Data store memory

  • Persistent variables

MATLAB Function block settings
  • Function packaging (RTWSystemCode) set to Inline. If you select Nonreusable function, the subsystem must be in the following configurations:

    • Set Function name options to User Specified.

    • Set Function interface to void-void.

    • Set Function with separate data to off.

    • Set model parameter Code interface packaging to Nonreusable function.

    If you select Reusable function, the model must use the following configurations:

    • Pass reusable subsystem outputs as to Individual arguments

    • Set model parameter Code interface packaging to Nonreusable function.

  • Saturate on integer overflow (SaturateOnIntegerOverflow) parameter cleared (set to off)

MATLAB® operations - scalar
  • Arithmetic: uminus, uplus, minus, plus, and multiplication

  • Relational: >, >=, <, <=, ==, and ~=

  • Logical: &, |, &&, ||, and not

  • ldivide (.\) and rdivide (./) - floating-point and integer

  • power - floating point and integer

  • Transpose (', .').

MATLAB operations - vector support
  • Array and matrix support for element-wise operators.

  • Assignment statements, such as y = u, for vectors or matrices of the same size.

  • Array subscripting.

  • colon (:) operator for integer or double data and no more than 3 operands.

  • Concatenation of nonvariable size scalar arrays.

  • Matrix multiplication (*).

  • Transpose (', .').

MATLAB program statements
  • Compound statements

  • If statements

  • for statements

  • switch statements

MATLAB built-in functions
  • cast

  • Direct cast for: int8, int16, int32, uint8, uint16, uint32, double, and single

  • true, false keywords

  • zeros and ones

  • coder.nullcopy

  • assert

  • Math functions (scalar and array support): rem, abs, sqrt, size, ceil, floor, fix, log, log10, exp, hypot, mod, round, pow2, min, max, sum and trigonometric functions (sin, cos, tan, asin, acos, atan, and atan2)

  • diag

  • eye

  • is* built-in functions: isempty, isscalar, isvector, ismatrix, isrow, iscolumn, isinteger, isfloat, islogical, and isnumeric

  • Bit-wise operations: bitand, bitcmp, bitget, bitor, bitset, bitshift, and bitxor

  • Matrix and array operations: dot, cross, length, mean, numel, prod, reshape, and nnz

  • sign

  • deg2rad

  • rad2deg

Functions
  • MATLAB block level functions.

  • Function calls to standalone user-defined functions.

  • Function calls to user-defined local functions.

  • Definitions of standalone functions and local functions that are compatible with Simulink Code Inspector.

  • Use of coder.inline('always') and coder.inline('never') directives.

  • coder.const

  • coder.ceval

Note

Simulink Code Inspector supports verification of the coder.ceval function in MATLAB Function blocks, which allows the model to call a C/C++ function from generated code. To enable this functionality, the C/C++ Source file and Header file are defined in the configuration parameters under Code Generation > Custom Code > Insert custom C code in generated. As a result of defining these parameters, compatibility check “Check code generation settings” fails with a non-fatal warning. In this situation, Simulink Code Inspector verifies these models even though they fail with a non-fatal constraint. You must manually review the external C/C++ files listed under the Utils Verification section of the Simulink Code Inspector Report.

ReportingBlock level traceability and verification
Mangled functionsVerification of mangled function names generated from a MATLAB Function block division expression. The Simulink Code Inspector report lists these functions so that you can manually verify the function body. Check the function body manually to be sure it is consistent with the function call.
Size and type verificationSimulink Code Inspector gets size and type information for variables in the code from the block’s simulation data. To independently verify type and size information, you can use Simulink Report Generator™ to generate a System Design Description (SDD) report for your model. Check the SDD report for MATLAB Function block symbol data such as size, complexity, position, and function call sites.

MATLAB Function Block Constraints divides the constraints into the following categories:

  • Constraints on the MATLAB Function block.

  • Constraints on the data in MATLAB functions.

  • Constraints on the code in MATLAB functions.

  • Constraints on MATLAB Code Analyzer messages.

A table provides the constraints that apply for each category.

For each entry in a table:

  • The Constraint column lists the Simulink Code Inspector constraint on the MATLAB Function block, data or code.

  • The FATAL / Nonfatal column identifies whether violation of the constraint terminates code inspection.

    • When you inspect code generated from models with a FATAL incompatibility, code inspection terminates. Code generated from models with FATAL incompatibilities cannot be verified.

    • When you inspect code generated from models with nonfatal incompatibilities, code inspection does not terminate. Although it might not be possible to fully verify the generated code, code inspection continues. The Simulink Code Inspector might partially verify the generated code. You can configure code inspection so that a nonfatal constraint violation terminates code inspection.

  • The Compatibility Check column lists the compatibility check that checks for violation of the constraint, and links to a description of the check.

Related Topics