Main Content

Check MATLAB Function metrics

Check ID: mathworks.hism.himl_0003

Display complexity and code metrics for MATLAB® Functions. Report metric violations.

Description

This check provides complexity and code metrics for MATLAB Functions. The check reports two categories of metrics violations:

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

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

Available with Simulink® Check™.

Input Parameters

You can define the tolerance for these complexity parameters by using the Model Advisor Configuration Editor:

  • Maximum effective lines of code per function ― Effective lines do not include empty lines, comment lines, or lines containing only the end keyword. The default value is 60.

  • Minimum density of comments ― Density is ratio of comment lines to total lines of code. The default value is 0.2.

  • Maximum cyclomatic complexity per function ― Cyclomatic complexity is the number of linearly independent paths through the source code. The default value is 15.

Results and Recommended Actions

ConditionRecommended Action
MATLAB Function violates the complexity input parameters.

For the MATLAB Function:

  • If effective lines of code is too high, further divide the MATLAB Function.

  • If comment density is too low, add comment lines.

  • If cyclomatic complexity per function is too high, further divide the MATLAB Function.

Capabilities and Limitations

  • This check only analyzes the functions that are directly referenced by the Simulink model.

  • Runs on library models.

  • Analyzes content of library-linked blocks. By default, the input parameter Follow links is set to on.

  • Analyzes content in masked subsystems. By default, the input parameter Look under masks is set to all.

  • Allows exclusions of blocks and charts.

See Also