Main Content

MATLAB Halstead Difficulty Distribution

Metric ID



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 distribution of MATLAB® Halstead difficulty across the MATLAB code in your units and components.

Computation Details

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


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

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


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 — Structure that represents the distribution of MATLAB Halstead difficulties in the unit or component. The structure contains these fields:

    • BinCounts — The number of MATLAB functions or methods in each bin, returned as a vector.

    • BinEdges — Bin edges for the MATLAB Halstead difficulties, returned as a vector. BinEdges(1) is the left edge of the first bin and BinEdges(end) is the right edge of the last bin. The length of BinEdges is one more than the length of BinCounts.

    For information on MATLAB Halstead difficulty, see MATLAB Halstead Difficulty.

  • Scope — Structure with information about the unit or component.

See Also

| |

Related Topics