主要内容

himl_0003: Complexity of user-defined MATLAB Functions

R2026b

Limit the size and complexity of MATLAB function code

Usage: High-Integrity System Modeling

Guideline ID: himl_0003

Rules

himl_0003: Complexity of user-defined MATLAB® Functions

When using MATLAB functions, limit the size and complexity of MATLAB code. The size and complexity of MATLAB functions is characterized by:

  • Lines of code

  • Nested function levels

  • Cyclomatic complexity

  • Density of comments (ratio of comment lines to lines of code)

Rationale

  • Readability

  • Comprehension

  • Traceability

  • Maintainability

  • Testability

Verification

Check MATLAB Function metrics (Simulink Check)

Tips

  • Size and complexity limits can vary across projects. Typical limits might be as described in this table:

    MetricLimit
    Lines of code60 per MATLAB function
    Nested function levels31,2
    Cyclomatic complexity15
    Density of comments0.2 comment lines per line of code

    1Pure Wrappers to external functions are not counted as separate levels.

    2Standard MATLAB library functions do not count as separate levels.

Industry Standards

  • IEC 61508-3, Table B.9 (6) - Fully defined interface

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1a) - Enforcement of low complexity
    ISO 26262-6, Table 1 (1f) - Use of unambiguous graphical representation

  • EN 50128, Table A.1(11) - Software Interface Specifications

  • EN 50657, Table A.1(11) - Software Interface Specifications

  • EN 50716, Table A.1(11) - Software Interface Specifications

  • DO-331, Sections MB.6.3.1.e - High-level requirements conform to standards
    DO-331, Sections MB.6.3.2.e - Low-level requirements conform to standards

Version History

Introduced in R2013a

expand all