Main Content

Check MATLAB Function metrics

mathworks.hism.himl_0003

Dependencies: Simulink® Check™

Usage: High-Integrity System Modeling

Guideline: himl_0003: Complexity of user-defined MATLAB Functions

Description

Use this check to provide complexity and code metrics for MATLAB® functions.

This check reports two categories of metrics violations:

  • Block-based metrics ― Metrics for the entire code of the MATLAB Function block

  • Function-based metrics ― Metrics for each function of the MATLAB Function block, considered individually

Check Parameters

Use the Model Advisor Configuration Editor to define the scope of the analysis by specifying the input parameters.

ParameterDescription
Check external .m files referenced in the model

Specify whether to run on referenced MATLAB files in the model.

on (default) | off

Follow links

Specify whether to include content of library-linked blocks in the analysis.

on (default) | off

Look under masks

Specify whether to include masked model elements in the analysis.

all (default) | none | graphical | functional

  • all — Check analysis includes all masked model elements.

  • none — Check analysis excludes masked model elements.

  • graphical — Check analysis includes only the graphical masked model elements.

  • functional — Check analysis includes only the functional masked model elements.

Maximum effective lines of code per function

Specify the maximum number of effective code lines per function that does not include empty lines, comment lines, or lines containing only the end keyword.

60 (default)

Minimum density of comments

Specify the minimum ratio of comment lines to total lines of code.

0.2 (default)

Maximum cyclomatic complexity per function

Specify the maximum number of linearly independent paths through the source code.

15 (default)

Recommended Actions and Results

Review the violations that are flagged by the check and the recommended action for fixing the issue. After applying the changes, save the model and rerun the check analysis.

Modeling ConditionRecommended Action
MATLAB function violates code and complexity metrics.

For the MATLAB function:

  • If the number of non-comment lines of code is too high, divide the function into multiple functions with fewer lines of code than the original function.

  • If comment density is too low, add additional comments that describe the code.

  • If cyclomatic complexity per function is too high, divide each function into separate functions with fewer linearly independent paths through the source code than the original function.

Capabilities and Limitations

  • Analyzes only the functions that are directly referenced by the Simulink model

  • Runs on library models

  • Allows exclusions of blocks and charts

  • Analyzes both active and inactive variant choices

  • Does not require model compilation

Version History

Introduced in R2016a