slcoverage.MetricSelector class

Package: slcoverage

Select metric criterion for coverage filter


Specify metric selection criteria for a filter rule.


sel = slcoverage.MetricSelector(type,element,objIndex,outIndex)specifies the model element and the block metrics to create the rule for. Specify whether the type of selector is a condition or decision outcome. Then select the object and outcome index combination to specify the metric that you want to write the filter rule for.

You can create only a justify rule for a metric selector. You cannot create an exclude rule.

For more information on the condition and decision coverage tables produced in the report, see Top-Level Model Coverage Report.

Input Arguments

expand all

Metric selector type, specified as:

  • slcoverage.MetricSelectorType.ConditionOutcome selects outcome metrics related to block inputs.

  • slcoverage.MetricSelectorType.DecisionOutcome selects outcome metrics related to block outputs.

  • slcoverage.MetricSelectorType.RelationalBoundaryOutcome selects outcome metrics related to relational boundary outcomes.

  • slcoverage.MetricSelectorType.SaturationOverflowOutcome selects outcome metrics related to saturation on integer overflow outcomes.

Model element to select, specified as a handle or the model element Simulink® identifier.

Example: 'sldemo_lct_bus:18'

Matrix position of objective to select, specified as an integer that corresponds to the row of the coverage table.

Example: 1

Matrix position of the outcome to select, specified as an integer that corresponds to the column of the coverage table.

Example: 2


expand all

This property is read-only.

Code used to create this selector object, returned as a character vector.

This property is read-only.

Description of the selector, returned as a character vector. Simulink Coverage™ creates the description based on the selector.

This property is read-only.

Identifier of the model element, returned as character vector of the Simulink ID or handle.

This property is read-only.

Matrix position of objective for this selector, returned as an integer.

This property is read-only.

Matrix position of outcome for this selector, returned as an integer.

This property is read-only.

Selector type, returned as ConditionOutcome, DecisionOutcome, RelationalBoundaryOutcome, or SaturationOverflowOutcome.


expand all

Selector object, returned as an slcoverage.MetricSelector object or array of slcoverage.MetricSelector objects.


allSelectorsSelectors for model or code element

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).


collapse all

Select a metric, create a rule for it, and add the rule to a filter. Then you can simulate the model for code coverage using the filter to see the effect.

In this example, you create a rule to justify the untested condition for the And block.

Open the model. Specify coverage settings and turn on coverage recording.

modelName = 'sldemo_lct_bus';

Get the identifier for the And block. Create the metric selector for the block. For this example, filter the second condition (input port 2) False outcome, whose index, then, is 2,2. Use the ConditionOutcome selector type and the index 2,2.

id = Simulink.ID.getSID('sldemo_lct_bus/slCounter/And');
metr = slcoverage.MetricSelector(slcoverage.MetricSelectorType.ConditionOutcome,id,2,2);

Create a filter object and create a rule using the default filter mode of justify. Add the rule to the filter.

filt = slcoverage.Filter;
rule = slcoverage.FilterRule(metr,'Expected result');

Save the filter as metrfilter. Simulate the model for code coverage. Add the filter file as the value to the filter property of the resulting cvdata object. Then generate the coverage report.'metrfilter');
csim = cvsim(modelName);
csim.filter = 'metrfilter';

Examine the HTML report and view the condition table for the And block. The report now shows 100% coverage for the condition and that the untested condition was justified.

Introduced in R2017b