Main Content

slcoverage.BlockSelector class

Package: slcoverage

Select blocks for coverage filter


Specify block selection criteria for a filter rule.


sel = slcoverage.BlockSelector(type,element) specifies the type of model elements to create the filter rule for and returns an slcoverage.BlockSelector object.

Input Arguments

expand all

Type of model element to select, specified as one of these values:

  • 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.

Example: slcoverage.BlockSelectorType.Transition

Model element to select, specified as a property name of the element, its handle, or its Simulink identifier. Use a handle or ID for selector types that select an instance. Use a property name, such as the value of a block's 'BlockType' property, to select multiple model elements.

Example: 'slcoverage_lct_bus:18', 'RelationalOperator'




Data Types: char | string | handle | integer


expand all

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


expand all

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




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




Model element identifier, specified as the property name of the element, the handle to an element, or the Simulink identifier of the element. Use a handle or ID for selector types that select an instance. Use a property name, such as the value of the 'BlockType' property of a block, to select multiple model elements.




Data Types: char | string | handle | integer

This property is read-only.

Selector type, returned as one of these slcoverage.BlockSelectorType values:

  • BlockInstance

  • BlockType

  • Chart

  • MaskType

  • State

  • StateAllContent

  • StateflowFunction

  • Subsystem

  • SubsystemAllContent

  • TemporalEvent

  • Transition


allSelectorsSelectors for model or code element

Copy Semantics

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


collapse all

Select multiple blocks to add a rule for and an instance of a block to add a rule for. The resulting filter has two rules. You can simulate your model for code coverage using the filter to see the effect.

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

modelName = 'slcoverage_lct_bus';

Select blocks that have the same block type as the upper GE input block to add a filter rule for.

type = get_param('slcoverage_lct_bus/slCounter/upper GE input','BlockType');
bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockType,type);

Create a filter object, create a rule based on the selector, and add the rule to the filter.

filt = slcoverage.Filter;
rule = slcoverage.FilterRule(bl,'Tested elsewhere',slcoverage.FilterMode.Exclude);

Select a block instance and add a rule for the block instance to the filter. This rule uses the default filter mode of Justify.

id = Simulink.ID.getSID('slcoverage_lct_bus/slCounter/And');
bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockInstance,id);
rule = slcoverage.FilterRule(bl,'Edge case');

Save the filter as blfilter. 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.'blfilter');
csim = cvsim(modelName);
csim.filter = 'blfilter';

Examine the HTML report to see information about the blocks that you added rules for.

Introduced in R2017b