execute
R2026bCollect metric results
Description
collects results in the specified results = execute(metricEngine,metricIDs)metric.Engine object for the metrics
that you specify in metricIDs.
There is also a function execute (Fixed-Point Designer) in
the Fixed-Point Designer™ documentation.
specifies options using one or more name-value arguments in addition to the input arguments
in previous syntaxes. For example, you can specify the results = execute(___,Name=Value)ScopeId to
collect metrics for a specific artifact in your project.
Examples
Collect metric results on the design artifacts in a project.
Open a project containing models that you want to analyze. For this example, in the MATLAB® Command Window, enter:
openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample"); openProject("cc_CruiseControl");
Create a metric.Engine object. To collect the metric results for the
current project, use the metric.Engine object.
metricEngine = metric.Engine();
To collect results for a model design metric, execute the metric engine. The
execute function returns the collected results. For more information on
the model design metrics, see Model Design Metrics and Model Maintainability Metrics.
results = execute(metricEngine,"sldesignlayer.SimulinkDesignInfo")results =
1x45 Result array with properties:
UserData
Value
MetricID
Artifacts
ScopeId
ScopeAlias
ThresholdOutcomes
DiagnosticsTo access the metric results data, use the properties of the
metric.Result objects in the results array. For this
metric, the Value property is a structure containing design information for
each component in the model.
v = results(1).Value
v =
struct with fields:
Blocks: 7
Decisions: 4
Gotos: 0
InterfacePorts: [1x1 struct]
SignalLines: 18
Halstead: [1x1 struct]v.InterfacePorts
ans =
struct with fields:
In: 3
Out: 1v.Halstead
ans =
struct with fields:
TotalOperators: 11
UniqueOperators: 7
TotalOperands: 15
UniqueOperands: 12
Volume: 110.4461
Difficulty: 4.3750Display specific design information across all model layers by building a table from the results.
modelLayers = [results.ScopeAlias].'; values = [results.Value].'; signalLines = [values.SignalLines].'; T = table(modelLayers,signalLines,VariableNames=["Model Layer","Signal Lines"])
T =
45×2 table
Model Layer Signal Lines
_____________________________________ ____________
"Target_Speed_Calculator" 18
"Switch Case Action↵Subsystem3" 1
"Transitions_From_THROTTLE_OVERRIDE" 14
...To access collected results or a subset of those results after execution, use
getMetrics.
results = getMetrics(metricEngine,"sldesignlayer.SimulinkDesignInfo");Model design metrics provide high-level design information about models. Model maintainability metrics provide more detailed metric results. For more information on how to collect metrics for design artifacts, see Collect Model Maintainability Metrics Programmatically.
Collect metric results on the requirements-based testing artifacts in a project.
Open a project that contains models and testing artifacts. For this example, in the MATLAB Command Window, enter:
openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample"); openProject("cc_CruiseControl");
Create a metric.Engine object. You can use the
metric.Engine object to collect metric results for the current
project.
metricEngine = metric.Engine();
Collect results for model testing metrics by executing the metric engine. The
execute function returns the collected results.
results = execute(metricEngine,"modeltesting.TestAnalysis[]")results =
1x44 Result array with properties:
UserData
Value
MetricID
Artifacts
ScopeId
ScopeAlias
ThresholdOutcomes
DiagnosticsUse getMetrics to access a subset of the collected results. For
example, get only the results for the ratio of requirements per test.
reqsPerTest = getMetrics(metricEngine,"modeltesting.TestAnalysis[slcomp.RequirementsPerTestRatio]")reqsPerTest =
1x4 Result array with properties:
UserData
Value
MetricID
Artifacts
ScopeId
ScopeAlias
ThresholdOutcomes
DiagnosticsAccess the metric results data by using the properties of the
metric.Result objects in the array. For this metric, the
Value property is a structure containing the total, linked, and
unlinked requirement counts.
reqsPerTest(1).Value
ans =
struct with fields:
Total: 37
Linked: 37
Unlinked: 0reqsPerTest(1).ScopeAlias
ans =
"cc_ControlMode"Display the ratio of requirements per test for each unit model in the project.
models = [reqsPerTest.ScopeAlias].'; values = [reqsPerTest.Value].'; total = [values.Total].'; linked = [values.Linked].'; unlinked = [values.Unlinked].'; T = table(models,total,linked,unlinked,VariableNames=["Model","Total","Linked","Unlinked"])
T =
4x4 table
Model Total Linked Unlinked
____________________ _____ ______ ________
"cc_ControlMode" 37 37 0
"cc_LightControl" 5 5 0
"cc_DriverSwRequest" 10 10 0
"cc_ThrottleController" 0 0 0For more information on how to collect metrics for testing artifacts, see Collect Metrics on Model Testing Artifacts Programmatically.
Collect metrics for one unit in the project. Specify a model and collect metrics for only the artifacts that trace to the model.
Open the project that contains the model. For this example, in the MATLAB Command Window, enter:
openExample("slcheck/ExploreTestingMetricDataInModelTestingDashboardExample"); openProject("cc_CruiseControl");
Create a metric.Engine object for the project.
metric_engine = metric.Engine();
Update the trace information for metric_engine to
ensure that the artifact information is up to
date.
updateArtifacts(metric_engine)
Open the model cc_DriverSwRequest and find the digital thread URI
for that model.
open_system("cc_DriverSwRequest"); storageMap = digitalthread.StorageMap.forProject(); modelURI = digitalthread.uri.simulink.fromObject(storageMap,get_param(gcs,"Handle"))
Collect results for a model testing metric by using the
execute function on the engine object and limiting the scope to
the cc_DriverSwRequest model.
results = execute(metric_engine,"modeltesting.TestAnalysis[slcomp.RequirementsPerTestRatio]",ScopeId=modelURI)Access the metric results data by using the properties of the
metric.Result object.
results.Value
ans =
struct with fields:
Total: 10
Linked: 10
Unlinked: 0You can scope metric result collection to a specific artifact by using a digital thread URI. A digital thread URI uniquely identifies an artifact, such as a model, subsystem, or block, so that the metric engine collects results only for that artifact.
Get the digital thread URI for the artifact that you want to collect metrics for.
You can find digital thread URIs by using the functions in the
digitalthread.uri namespace. For example, to find the digital
thread URI for a subsystem that you select in a Simulink® model:
storageMap = digitalthread.StorageMap.forProject();
subsystemURI = digitalthread.uri.simulink.fromObject(storageMap,get_param(gcb,"Handle"))subsystemURI =
"mwdigitalthread://myProject/myModel.slx#addr=myModel/123"Collect metrics for that specific subsystem by passing the artifact URI to the
ScopeId
argument.
metricID = "sldesignlayer.SimulinkDesignInfo";
results = execute(metric_engine,metricID,ScopeId=subsystemURI)results =
Result with properties:
UserData: ''
Value: [1×1 struct]
MetricID: 'sldesignlayer.SimulinkDesignInfo'
Artifacts: [1×1 struct]
ScopeId: "mwdigitalthread://myProject/myModel.slx#addr=myModel/308"
ScopeAlias: "mySubsystem"
ThresholdOutcomes: [1×0 metric.threshold.ThresholdOutcome]
Diagnostics: []Input Arguments
Metric engine object for which you want to collect metric results, specified as a
metric.Engine object.
Metric identifiers for metrics that you want to collect, specified as a character vector, cell array of character vectors, string, or string array.
You can use the function getAvailableMetricIds to return a list of
available metric identifiers.
For information on the metrics and their identifiers, see:
Example: 'slcomp.OverallCyclomaticComplexity'
Example: {'slcomp.OverallMATLABeLOC',
'slcomp.OverallSignalLines'}
Example: 'TestCasesPerRequirementDistribution'
Example: {'slcomp.mt.TestStatus',
'slcomp.mt.CoverageBreakdown'}
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: results = execute(metric_engine,"modeltesting.TestAnalysis[slcomp.RequirementsPerTestRatio]",ScopeId=modelURI)
Digital thread URI for the artifact that you want to collect metric results for, specified as a string scalar.
A digital thread URI is a stable identifier for an
artifact, such as a model file, or a sub-file artifact, such as a block. The digital
thread uses these URIs as a consistent way to refer to artifacts across tools and
inside metric results. The scopes that a metric supports depend on the metric. Check
the metric documentation to learn what scopes a metric operates on, and use the
appropriate function from the digitalthread.uri namespace to get the
URI for the artifact. For example, use digitalthread.uri.simulink.fromObject to get the URI for a model or
element within a model.
Note
If you specify both ScopeId and
ArtifactScope, ScopeId takes
precedence.
Note
For table metrics (metrics that use the bracket notation, such as
"modeldesign.SimulinkMaintainability[slcomp.BlockDistribution]"),
specifying ScopeId does not limit the scope of the table metric
itself. The table metric still collects results across all scopes. The
ScopeId argument only limits the collection of dependent
metrics that the table metric imports. For non-table metrics,
ScopeId limits the collection to the specified
artifact.
Example: "mwdigitalthread://myProject/myModel.slx#addr=myModel/###"
Data Types: string
Since R2026b
Threshold set identifier, specified as a string scalar. Use this argument to classify metric results according to a specific threshold set. The threshold set determines how metric values are classified into compliance categories.
The shipping threshold sets are "Testing" and
"ReqBasedTesting". You can also specify custom threshold sets
that you create by using on a metric.config.Configuration.copyThresholdSetmetric.config.Configuration object.
Example: "Testing"
Example: "MyTestingThresholds"
Data Types: string
Output Arguments
Metric results, returned as an array of metric.Result
objects.
When you execute a table metric with a specific sub-metric identifier, such as
"modeltesting.TestAnalysis[slcomp.TestTagDistribution]", the
Value property of the result contains the sub-metric identifier as a
field name. For example, results.Value.TestTagDistribution.
Alternative Functionality
App
You can also collect metric results by using the dashboard user interface.
For the model design metrics, use the Model Design Dashboard. For more information, see Model Design Metrics.
For the model maintainability metrics, use the Model Maintainability dashboard. For more information, see Monitor Design Complexity Using Model Maintainability Dashboard.
For the model testing metrics, use the Model Testing Dashboard. For more information, see Explore Status and Quality of Testing Activities Using Model Testing Dashboard.
For the code testing metrics, use the SIL Code Testing or PIL Code Testing dashboard. For more information see, View Status of Code Testing Activities for Software Units in Project.
Version History
Introduced in R2020bIn R2026b, you can specify the ThresholdSetId name-value argument
to classify metric results according to a specific threshold set. You can use shipping
threshold sets or custom threshold sets that you create by using .metric.config.Configuration.copyThresholdSet
In R2026b, you can scope metric execution to a single artifact by using the new
ScopeId argument. The ScopeId argument replaces
ArtifactScope, which is not recommended.
In releases prior to R2026b, you use the ArtifactScope argument by specifying:
The full path to a project file, such as a model file.
The identifier of the object inside the project file, such as a block diagram name.
For example:
| Prior to R2026a | R2026 and later |
|---|---|
modelPath = fullfile(pwd,'myModel.slx'); execute(metricEngine,metricID,ArtifactScope={modelPath,'myModel'}); |
open_system("myModel"); storageMap = digitalthread.StorageMap.forProject(); modelURI = digitalthread.uri.simulink.fromObject(storageMap,get_param(gcs,"Handle")); results = execute(metricEngine,metricID,ScopeId=modelURI) |
Starting in R2026a, the execute function returns a
metric result object if there are
any results. Previously, you
needed to use the getMetrics function
to get metric results from the metric engine.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)