This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Class: slmetric.Engine
Package: slmetric

Access model metric data


Results = getMetrics(metric_engine)
Results = getMetrics(metric_engine,MetricIDs)
Results = getMetrics(metric_engine,MetricIDs,'AggregationDepth',ad)


Access model metric data from the specified model metric engine. When you call execute, the metric engine collects the metric data. The returned metric data is based on defined architectural components. The components are these Simulink objects:

  • Model

  • Subsystem block

  • Chart

  • MATLAB Function block

  • Protected model


Results = getMetrics(metric_engine) returns metric data for all metrics that the metric engine executed.

Results = getMetrics(metric_engine,MetricIDs) returns metric data for the specified metric identifiers.

Results = getMetrics(metric_engine,MetricIDs,'AggregationDepth',ad) returns metric data for the specified metric identifiers and specifying how to aggregate data.

Input Arguments

expand all

When you call execute, metric_engine collects metric data for all available MathWorks metrics or for the specified MetricIDs. Calling getMetrics accesses the collected metric data in metric_engine.

Metric identifier for Model Metrics or custom model metrics that you create. You can specify one or multiple metric identifiers. You can get metric identifiers by calling slmetric.metric.getAvailableMetrics.

Example: 'mathworks.metrics.DescriptiveBlockNames'

Depth or level in the component for which getMetrics aggregates the metric data, specified as a name-value pair argument. Values are one of the following:

  • AllgetMetrics aggregates the detailed results to the component level. Then, the component level results are used to calculate the aggregated values by traversing the component hierarchy. getMetrics returns only the component-level results.

  • None — Do not aggregate measures and values. If you specify this option, getMetrics returns metric values as collected by the metric algorithm. For example, if the metric algorithm returns detailed results, the detailed results are returned without aggregation. AggregatedValue and AggregatedMeasures properties of the returned slmetric.metric.Result objects are empty.

Example: 'AggregationDepth','None'

Data Types: char

Output Arguments

expand all

Metric data from the metric engine.


expand all

Collect and access model metric data for the model sldemo_mdlref_basic.

Create an slmetric.Engine object and set the root in the model for analysis.

metric_engine = slmetric.Engine();

% Include referenced models and libraries in the analysis.
% These properties are on by default.
metric_engine.AnalyzeModelReferences = 1;
metric_engine.AnalyzeLibraries = 1;

setAnalysisRoot(metric_engine, 'Root',  'sldemo_mdlref_basic');

Collect model metric data

execute(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

Get the model metric data that returns an array of slmetric.metric.ResultCollection objects, res_col.

res_col = getMetrics(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

Display the results for the mathworks.metrics.SimulinkBlockCount metric.

for n=1:length(res_col)
    if res_col(n).Status == 0
        result = res_col(n).Results;
        for m=1:length(result)
            disp(['MetricID: ',result(m).MetricID]);
            disp(['  ComponentPath: ', result(m).ComponentPath]);
            disp(['  Value: ', num2str(result(m).Value)]);
            disp(['  AggregatedValue: ', num2str(result(m).AggregatedValue)]);
        disp(['No results for:', result(n).MetricID]);
    disp(' ');

Introduced in R2016a