Main Content

MATLAB Decision Distribution

R2026b
Since R2026b

Metric ID

modeldesign.MATLABMaintainability[slcomp.DecisionDistribution]

Description

This metric returns a histogram showing how many MATLAB® design layers in each unit fall into each decision count range. Decisions are branch points in MATLAB code, such as if, elseif, switch, case, while, and for statements. Use this metric to identify units where MATLAB code has high decision complexity.

Supported Artifacts

This metric collects metric results for Units in the project. To control what the dashboard classifies as a unit, see Categorize Models in Hierarchy as Components or Units.

Decision Counts for Common MATLAB Keywords

The following table shows how the metric calculates the decision count for common MATLAB keywords. The metric uses the cyclomatic complexity value from the checkcode function. For more information on the cyclomatic complexity value, see Measure Code Complexity Using Cyclomatic Complexity.

OperatorDecision Count
& operator1, only counted in while, if, and elseif conditions
&& operator1
| operator1, only counted in while, if, and elseif conditions
|| operator1
break0
case1
catch0
continue0
else0
for/parfor1
if/elseif1
otherwise0
return0
switch0
try1
while1

Computation Details

The metric:

  • Calculates the number of decisions in MATLAB code by taking the cyclomatic complexity calculated by the Code Analyzer and subtracting one to exclude the default path. For more information, see checkcode and Measure Code Complexity Using Cyclomatic Complexity.

  • Counts decisions from if, elseif, while, for, parfor, try, and case statements.

  • Ignores else, otherwise, and catch statements because they form the default path.

  • Does not compile the model. The metric only considers static information.

  • Only analyzes MATLAB code that does not contain syntax errors.

Collection

To collect data for this metric, execute the metric engine with the metric ID.

metric_engine = metric.Engine;
results = execute(metric_engine,"modeldesign.MATLABMaintainability[slcomp.DecisionDistribution]")

View the metric result values for a specific unit.

results(1).Value
results(1).ScopeAlias

You can also collect all MATLAB maintainability metrics at once by using the group ID.

results = execute(metric_engine,"modeldesign.MATLABMaintainability[]")
Use the MetricID property of each result to identify which metric the result belongs to.

Results

The metric returns an array of metric.Result objects, one for each unit in the project. Use the Value property of the metric result object to view the metric result values. Use the ScopeId and ScopeAlias properties to identify which unit the result belongs to.

The ScopeAlias property returns the name of the unit.

The Value property returns an array of structures representing a histogram. Each structure has these fields:

  • BinEdge — The decision count range for the bin, such as '0-9' or '>99'

  • BinCount — The number of MATLAB design layers in the unit whose decision count falls within this range

See Also

Topics