Main Content

MATLAB Halstead Difficulty

Since R2024a

Metric ID

slcomp.MATLABHalsteadDifficulty

Description

The Halstead complexity metrics measure the size and complexity of code, which can help you monitor code quality, identify complex areas in the design, and address software maintainability concerns. One of the Halstead complexity metrics is Halstead difficulty. Halstead difficulty is an estimate of how difficult the code is to read and write, calculated based on the number of total and unique operators and operands in the design.

Use this metric to calculate the Halstead difficulty of the MATLAB® code in your units and components.

Supported Artifacts

You can collect this metric for:

To control what the dashboard classifies as a unit or component, see Categorize Models in Hierarchy as Components or Units.

Computation Details

For information on how the metric calculates the metric results, see MATLAB Halstead Complexity.

Collection

To collect data for this metric, execute the metric engine and use getMetrics with the metric ID slcomp.MATLABHalsteadDifficulty.

metric_engine = metric.Engine;
execute(metric_engine,"slcomp.MATLABHalsteadDifficulty");
results = getMetrics(metric_engine,"slcomp.MATLABHalsteadDifficulty")

Results

The metric returns results for each unit and component in the project.

For each unit and component, the metric returns a metric.Result object with properties including:

  • Value — MATLAB Halstead difficulty for the unit or component

  • Scope — Structure with information about the unit or component

To get the distribution of MATLAB Halstead difficulty, see MATLAB Halstead Difficulty Distribution.

For detailed metric results, including the number of total and unique operators and operands, see MATLAB Halstead Complexity.

See Also

| |

Related Topics