Cyclomatic Complexity Metric
Metric ID
Metric ID:
mathworks.metrics.CyclomaticComplexity
Description
Metric Type: Architecture
Model Advisor Check ID:
mathworks.metricchecks.CyclomaticComplexity
Use this metric to calculate the cyclomatic complexity of the model. Cyclomatic complexity is a measure of the structural complexity of a model. The complexity measure can be different for the generated code than for the model due to code features that this analysis does not consider, such as consolidated logic and error checks. To compute the cyclomatic complexity of an object (such as a block, chart, or state), Simulink® Check™ uses this formula:
N is the number of decision points that the object represents and on is the number of outcomes for the nth decision point. The calculation considers a vectorized operation or a Multiport switch block as a single decision point. The tool adds 1 to the complexity number for models, atomic subsystems, and Stateflow® charts.
The results provide the local and aggregated cyclomatic complexity for the:
Model
Subsystems
Charts
MATLAB® functions
Local complexity is the cyclomatic complexity for objects at their hierarchical level. Aggregated cyclomatic complexity is the cyclomatic complexity of an object and its descendants
This metric is available with Simulink
Check. To collect data for this metric, use getMetrics
with the metric identifier,
mathworks.metrics.CyclomaticComplexity
.
The slmetric.metric.AggregationMode
property setting is
Sum
.
Computation Details
The metric:
Does not run on library models.
Analyzes content in masked subsystems.
Does not analyze inactive variants.
If specified, analyzes the content of library-linked blocks or referenced models.
Does not analyze referenced models in accelerated mode.
Collection
To collect data for this metric using the Model Advisor, run the check, Cyclomatic complexity metric in By Task > Model Metrics > Complexity Metrics. The Model Advisor check displays the local cyclomatic complexity for the root model and for Simulink and Stateflow objects in the system. The check does not analyze referenced models or return aggregated results.
Results
For this metric, instances of slmetric.metric.Result
provide the
following results:
Value
: Local cyclomatic complexity.AggregatedValue
: Aggregated cyclomatic complexity.Measures
: Not applicable.
For more information on complexity, see:
Cyclomatic Complexity for Stateflow Charts (Simulink Coverage)
Specify Coverage Options (Simulink Coverage)