Main Content

Check MATLAB Function metrics

Check ID: mathworks.maab.himl_0003

Guideline:

Description

This check provides complexity and code metrics for MATLAB® Functions. The check additionally reports metric violations.

A results table provides links to MATLAB Functions that violate the complexity input parameters.

This check requires a Simulink® Check™ license.

Check Parameterization

This Model Advisor check is not applicable for JMAAB modeling guidelines.

This check does not include sub-checks

For reference, the MAB guideline sub ID(s) that are recommended for use by the NA-MAAB and JMAAB modeling standards organizations are:

  • NA-MAAB — a

  • JMAAB — Not supported

To specify the complexity thresholds, use the Model Advisor Configuration Editor.

  1. Open the Model Configuration Editor and search for check ID himl_0003.

  2. Under Input Parameters, select Check .m files referenced in the model to include files with a .m extension in the analysis.

  3. Define these complexity metrics:

    • Maximum effective lines of code per function — Provide the maximum effective lines of code per function. Effective lines do not include empty lines, comment lines, or lines with a function end keyword.

    • Minimum density of comments — Provide minimum density of comments. Density is ratio of comment lines to total lines of code.

    • Maximum cyclomatic complexity per function — Provide maximum cyclomatic complexity per function. Cyclomatic complexity is the number of linearly independent paths through the source code.

  4. Click Apply and save the configuration.

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

  • Runs on library models.

  • Does not analyze content of library linked blocks.

  • Analyzes content in all masked subsystems.

  • Allows exclusions of blocks and charts.