Hauptinhalt

metric.Result

R2026b

Results from specified metric

Description

A metric.Result object contains the results for a specified metric.

Creation

Description

metric_result = metric.Result creates a handle to a metric result object.

Alternatively, if you collect results by executing a metric.Engine object, using the getMetrics function on the engine object returns the collected metric.Result objects in an array.

example

Properties

expand all

User data provided by the metric algorithm, returned as a string.

Value of the metric result for the specified metric and artifacts, returned as an integer, string, double vector, or structure. For a list of model testing metrics and their result values, see Model Testing Metrics.

Metric identifier for the metric that calculated the results, returned as a string.

Example: "modeltesting.TestAnalysis[slcomp.TestTagDistribution]"

Project artifacts for which the metric is calculated, returned as a structure or an array of structures. For each artifact that the metric analyzed, the returned structure contains these fields:

  • UUID — Unique identifier of the artifact.

  • Name — Name of the artifact.

  • ParentUUID — Unique identifier of the file that contains the artifact.

  • ParentName — Name of the file that contains the artifact.

Data Types: struct

Since R2026b

Digital thread URI of the unit or component for which the metric collected results, returned as a string. The ScopeId property identifies the scope using a digital thread URI instead of a structure of UUIDs.

Example: "mwdigitalthread://DO_Project/DO_03_Design/Flight_Control/specification/Flight_Control.slx#addr=Flight_Control"

Data Types: string

Since R2026b

Display name of the unit or component for which the metric collected results, returned as a string.

Example: "Flight_Control"

Data Types: string

Since R2026b

Threshold classification outcomes for the metric result, returned as an array of metric.threshold.ThresholdOutcome objects. Each object contains the threshold classification for a specific threshold rule applied to the metric result.

To populate this property, specify the ThresholdSetId argument when you call getMetrics or execute.

Data Types: metric.threshold.ThresholdOutcome

Since R2025a

Errors and warnings from the metric collection, returned as a structure or an array of structures. Each structure contains these fields:

  • Severity — Severity of the diagnostic message, returned as either "ERROR" or "WARNING".

  • Identifier — Identifier for the diagnostic message.

  • Message — Diagnostic message.

Data Types: struct

Examples

collapse all

Use a metric.Engine object to 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
    Diagnostics

To 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: 1
v.Halstead
ans =

  struct with fields:

     TotalOperators: 11
    UniqueOperators: 7
      TotalOperands: 15
     UniqueOperands: 12
             Volume: 110.4461
         Difficulty: 4.3750

Display 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. Then, access the data by using the metric.Result objects.

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
    Diagnostics

Use 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
    Diagnostics

Access 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: 0
reqsPerTest(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         0

For more information on how to collect metrics for testing artifacts, see Collect Metrics on Model Testing Artifacts Programmatically.

Version History

Introduced in R2020b

expand all