Main Content


Class: slcoverage.BlockSelector, slcoverage.CodeSelector, slcoverage.Selector, slcoverage.MetricSelector, slcoverage.SFcnSelector
Package: slcoverage

Selectors for model or code element


sel = slcoverage.Selector.allSelectors(element)
sel = slcoverage.BlockSelector.allSelectors(element)
sel = slcoverage.CodeSelector.allSelectors(element)
sel = slcoverage.CodeSelector.allSelectors(element,Name,Value)
sel = slcoverage.MetricSelector.allSelectors(element)
sel = slcoverage.SFcnSelector.allSelectors(element)
sel = slcoverage.Selector.allSelectors(element,Name,Value)


sel = slcoverage.Selector.allSelectors(element) returns all the selectors for the model element.

sel = slcoverage.BlockSelector.allSelectors(element) returns all the block selectors for element.

sel = slcoverage.CodeSelector.allSelectors(element) returns all the custom C/C++ code selectors for element.

sel = slcoverage.CodeSelector.allSelectors(element,Name,Value) , where element is a model and Name,Value specifies the simulation mode, returns all the custom C/C++ code selectors for the model in the specified simulation mode.

sel = slcoverage.MetricSelector.allSelectors(element) returns all the metric selectors for element.

sel = slcoverage.SFcnSelector.allSelectors(element) returns all the S-function selectors for element.

sel = slcoverage.Selector.allSelectors(element,Name,Value) returns selectors for element, with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

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

Example: 'sldemo_lct_bus:18'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Type',slcoverage.BlockSelectorType.BlockInstance,'Description','F outcome'

Selector type refinement specified as one of the slcoverage.BlockSelectorTypeslcoverage.CodeSelectorType, slcoverage.MetricSelectorType, or slcoverage.SFcnSelectorType values. Possible values:

  • Block selector types:

    • slcoverage.BlockSelectorType.BlockInstance — An instance of a block.

    • slcoverage.BlockSelectorType.BlockType — All blocks of the specified block type.

    • slcoverage.BlockSelectorType.Chart — A Stateflow® chart.

    • slcoverage.BlockSelectorType.MaskType — Blocks that use the specified mask type.

    • slcoverage.BlockSelectorType.State — A Stateflow state.

    • slcoverage.BlockSelectorType.StateAllContent — Stateflow state and its contents.

    • slcoverage.BlockSelectorType.StateflowFunction — A Stateflow function.

    • slcoverage.BlockSelectorType.Subsystem — A subsystem block.

    • slcoverage.BlockSelectorType.SubsystemAllContent — A subsystem and its contents.

    • slcoverage.BlockSelectorType.TemporalEvent — A Stateflow temporal event.

    • slcoverage.BlockSelectorType.Transition — A Stateflow transition.

  • Code selector types:

    • slcoverage.CodeSelectorType.File — A custom C or C++ code file name.

    • slcoverage.CodeSelectorType.Function — A custom C or C++ code function name.

    • slcoverage.CodeSelectorType.Decision — A custom C or C++ code decision.

    • slcoverage.CodeSelectorType.Condition — A custom C or C++ code condition.

    • slcoverage.CodeSelectorType.DecisionOutcome — A custom C or C++ code decision outcome.

    • slcoverage.CodeSelectorType.ConditionOutcome — A custom C or C++ code condition outcome.

    • slcoverage.CodeSelectorType.MCDCOutcome — A custom C or C++ code MCDC outcome.

    • slcoverage.CodeSelectorType.RelationalBoundaryOutcome — A custom C or C++ code relational boundary outcome.

  • Metric selector types:

    • slcoverage.MetricSelectorType.ConditionOutcome objects select condition metric objective outcomes.

    • slcoverage.MetricSelectorType.DecisionOutcome objects select decision metric objective outcomes.

    • slcoverage.MetricSelectorType.MCDCOutcome objects select MCDC metric objective outcomes.

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

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

  • S-function selector types:

    • slcoverage.SFcnSelectorType.SFcnName selects the specified S-function.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppFileName selects the coverage data in the generated code file for this block.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppFunction selects a function.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppCondition selects a condition outcome of the S-function block.

    • slcoverage.SFcnSelectorType.SFcnInstanceCppDecision selects a decision outcome of the S-function block.

Description text to match for the selector that you want to return, specified as a character vector or string. For example, if you want to return only the selectors that include the text F outcome in the description, use this syntax:

s = slcoverage.Selector.allSelectors(id,'Description','F outcome')

Simulation mode to run when selecting code filters, entered as one of the following:

Object SpecificationDescription

'normal' (default)

Extract code selectors for custom code in normal simulation, such as custom code called from a C Caller block or a Stateflow chart.


Extract code selectors for code generated in Simulation-in-the-Loop (SIL) mode and code selectors for the top model code interface


Extract code selectors for code generated in Processor-in-the-Loop (PIL) mode and code selectors for the top model code interface


If SIL-mode code exists, extract code selectors for code generated in SIL mode and extract code selectors for the top model code interface; otherwise, extract code selectors for code generated in PIL mode and extract code selectors for the top model code interface


Extract code selectors for the model reference code interface in SIL mode


Extract code selectors for the model reference code interface in PIL mode


If SIL-mode code exists, extract code selectors for the model reference code interface in SIL mode, if the model is in SIL mode; otherwise,extract code selectors for the model reference code interface in PIL mode

Output Arguments

expand all

Selectors for the model or code element, returned as an array of Selector objects.


expand all

This example shows how to get all the selectors for an And block and then add a rule to justify or exclude a selector. Metric selectors can only be justified.

Load the model and set coverage settings

modelName = 'slvnvdemo_covfilt';

First, get the block handle for the And block.

id = getSimulinkBlockHandle([modelName,'/Saturation']);

Get the selectors using the block handle.

sel = slcoverage.Selector.allSelectors(id)
sel = 

  1x10 heterogeneous Selector (BlockSelector, MetricSelector) array with properties:


The block has ten selectors. You can index into each one to see their contents. In this example, you want to justify the sixth selector.

ans = 

  MetricSelector with properties:

     ObjectiveIndex: 2
       OutcomeIndex: 2
        Description: 'T outcome of input >= upper limit in Saturate block "Saturation"'
               Type: DecisionOutcome
                 Id: 'slvnvdemo_covfilt:5'
    ConstructorCode: 'slcoverage.MetricSelector(slcoverage.MetricSelectorType.DecisionOutcome, 'slvnvdemo_covfilt:5', 2, 2)'

Create a justify rule, then create a filter object and add the rule to it.

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

Save the filter and generate a coverage report.'metrfilter');
csim = cvsim(modelName);
csim.filter = 'metrfilter';

This example shows how to get a selector by type and description. In this example, you get all selectors for the False outcomes of the And block whose type is ConditionOutcome.

Load the model into memory.

modelName = 'sldemo_lct_bus';

Get the false outcome condition selectors for the And block by searching for descriptions that include F.

id = getSimulinkBlockHandle([modelName,'/slCounter/And']);
sel = slcoverage.Selector.allSelectors(id, ...
         'Type',slcoverage.MetricSelectorType.ConditionOutcome, ...
sel = 

  1x2 MetricSelector array with properties:


Look at the constructor code for the two selectors that were returned.

ans =

    'slcoverage.MetricSelector(slcoverage.MetricSelectorType.ConditionOutcome, 'sldemo_lct_bus:23', 1, 2)'

ans =

    'slcoverage.MetricSelector(slcoverage.MetricSelectorType.ConditionOutcome, 'sldemo_lct_bus:23', 2, 2)'

Introduced in R2017b