Documentation Center

  • Trials
  • Product Updates

Simulink.BlockPath

Fully specified Simulink block path

Description

A Simulink.BlockPath object represents a fully specified block path that uniquely identifies a block within a model hierarchy, including model reference hierarchies that involve multiple instances of a referenced model. Simulink uses block path objects in a variety of contexts. For example, when you specify Normal mode visibility, Simulink uses block path objects to identify the models with Normal mode visibility. For details, see Set Normal Mode Visibility.

The Simulink.BlockPath class is very similar to the Simulink.SimulationData.BlockPath class.

You must have Simulink® installed to use the Simulink.BlockPath class. However, you do not have to have Simulink installed to use the Simulink.SimulationData.BlockPath class. If you have Simulink installed, consider using Simulink.BlockPath instead of Simulink.SimulationData.BlockPath, because the Simulink.BlockPath class includes a method for checking the validity of block path objects without you having to update the model diagram.

Property Summary

Name

Description

SubPath

Individual component within the block specified by the block path

Method Summary

Name

Description

BlockPath

Create a block path.

convertToCell

Convert a block path to a cell array of strings.

getBlock

Get a single block path in the model reference hierarchy.

getLength

Get the length of the block path.

validate

Determine whether the block path represents a valid block hierarchy.

Properties

SubPath

Description

Represents an individual component within the block specified by the block path.

For example, if the block path refers to a Stateflow® chart, you can use SubPath to indicate the chart signals. For example:

Block Path:
      'sf_car/shift_logic'
 
    SubPath:
      'gear_state.first'

Data Type

string

Access

RW

Methods

BlockPath

Purpose

Create block path

Syntax

blockpath_object = Simulink.BlockPath()
blockpath_object = Simulink.BlockPath(blockpath)
blockpath_object = Simulink.BlockPath(paths)
blockpath_object = Simulink.BlockPath(paths, subpath)

Input Arguments

blockpath

Block path object that you want to copy.

paths

A string or cell array of strings that Simulink uses to build the block path.

Specify each string in order, from the top model to the specific block for which you are creating a block path.

Each string must be a path to a block within the Simulink model. The block must be:

  • A block in a single model

  • A Model block (except for the last string, which may be a block other than a Model block)

  • A block that is in a model that is referenced by a Model block that is specified in the previous string

When you create a block path for specifying Normal mode visibility:

  • The first string must represent a block that is in the top model in the model reference hierarchy.

  • Strings must represent Model blocks that are in Normal mode.

  • Strings that represent variant models or variant subsystems must refer to an active variant.

You can use gcb in the cell array to specify the currently selected block.

subpath

String that represents an individual component within a block.

Output Arguments

blockpath_object

Block path that you create.

Description

blockpath_object = Simulink.BlockPath() creates an empty block path.

blockpath_object = Simulink.BlockPath(blockpath) creates a copy of the block path of the block path object that you specify with the source_blockpath argument.

blockpath = Simulink.BlockPath(paths) creates a block path from the cell array of strings that you specify with the paths argument. Each string represents a path at a level of model hierarchy. Simulink builds the full block path based on the strings.

blockpath = Simulink.BlockPath(paths, subpath) creates a block path from the string or cell array of strings that you specify with the paths argument and creates a path for the individual component (for example, a signal) of the block.

Example

Create a block path object called bp1, using gcb to get the current block.

sldemo_mdlref_depgraph
bp1 = Simulink.BlockPath(gcb)

The resulting block path is the top-level Model block called thermostat (the top-left Model block.

bp1 = 

  Simulink.BlockPath
  Package: Simulink

  Block Path:
    'sldemo_mdlref_depgraph/thermostat'

Create a block path object called bp2, using a cell array of strings representing elements of the block path.

sldemo_mdlref_depgraph
bp2 = Simulink.BlockPath({'sldemo_mdlref_depgraph/thermostat', ...
'sldemo_mdlref_heater/Fahrenheit to Celsius', ...
'sldemo_mdlref_F2C/Gain1'})

The resulting block path reflects the model reference hierarchy for the block path

bp2 = 

  Simulink.BlockPath
  Package: Simulink

  Block Path:
    'sldemo_mdlref_depgraph/thermostat'
      'sldemo_mdlref_heater/Fahrenheit to Celsius'
        'sldemo_mdlref_F2C/Gain1'

convertToCell

Purpose

Convert block path to cell array of strings

Syntax

cellarray = Simulink.BlockPath.convertToCell()

Output Arguments

cellarray

Cell array of strings representing elements of block path.

Description

cellarray = Simulink.BlockPath.convertToCell() converts a block path to a cell array of strings.

Examples

sldemo_mdlref_depgraph
bp2 = Simulink.BlockPath({'sldemo_mdlref_depgraph/thermostat', ...
'sldemo_mdlref_heater/Fahrenheit to Celsius', ...
'sldemo_mdlref_F2C/Gain1'}) 
cellarray_for_bp2 = bp2.convertToCell()

The result is a cell array representing the elements of the block path.

cellarray_for_bp2 = 

    'sldemo_mdlref_depgraph/thermostat'
    'sldemo_mdlref_heater/Fahrenheit to Celsius'
    'sldemo_mdlref_F2C/Gain1'

getBlock

Purpose

Get block path in model reference hierarchy

Syntax

block = Simulink.BlockPath.getBlock(index)

Input Arguments

index

The index of the block for which you want to get the block path. The index reflects the level in the model reference hierarchy. An index of 1 represents a block in the top-level model, an index of 2 represents a block in a model referenced by the block of index 1, and an index of n represents a block that the block with index n-1 references.

Output Arguments

block

The block representing the level in the model reference hierarchy specified by the index argument.

Description

blockpath = Simulink.BlockPath.getBlock(index) returns the block path of the block specified by the index argument.

Example

Get the block for the second level in the model reference hierarchy.

sldemo_mdlref_depgraph
bp2 = Simulink.BlockPath({'sldemo_mdlref_depgraph/thermostat', ...
'sldemo_mdlref_heater/Fahrenheit to Celsius', ...
'sldemo_mdlref_F2C/Gain1'})
blockpath = bp2.getBlock(2)

The result is the thermostat block, which is at the second level in the block path hierarchy.

blockpath =

sldemo_mdlref_heater/Fahrenheit to Celsius

getLength

Purpose

Get length of block path

Syntax

length = Simulink.BlockPath.getLength()

Output Arguments

length

The length of the block path. The length is the number of levels in the model reference hierarchy.

Description

length = Simulink.BlockPath.getLength() returns a numeric value that corresponds to the number of levels in the model reference hierarchy for the block path.

Example

Get the length of block path bp2.

sldemo_mdlref_depgraph
bp2 = Simulink.BlockPath({'sldemo_mdlref_depgraph/thermostat', ...
'sldemo_mdlref_heater/Fahrenheit to Celsius', ...
'sldemo_mdlref_F2C/Gain1'})
length_bp2 = bp2.getLength()

The result reflects that the block path has three elements.

length_bp2 =

     3

validate

Purpose

Determine whether block path represents valid block hierarchy

Syntax

Simulink.BlockPath.validate()
Simulink.BlockPath.validate(AllowInactiveVariant)

Input Arguments

AllowInactiveVariant

Set to true to include inactive variants in the validity checking. The default is false.

Description

Simulink.BlockPath.validate() determines whether the block path represents a valid block hierarchy. If there are any validity issues, messages appear in the MATLAB® command window. The method checks that:

  • All elements in the block path represent valid blocks.

  • All variant elements are active.

  • Each element except for the last element:

    • Is a valid Model block

    • References the model of the next element

Simulink.BlockPath.validate(AllowInactiveVariant) Specifying true causes the validity checking to consider inactive variants as being valid, if they meet the other validity checks described above. Omitting the AllowInactiveVariant argument or specifying its default value of false causes the method to check only the active variant.

Example

Validate the block paths, checking only the active variant. This validation fails, because the block path actually references model sldemo_mrv_nonlinear_controller, while bp specifies that the block references model sldemo_mdlref_second_order_controller, which is in an inactive variant.

sldemo_mdlref_variants
bp = Simulink.BlockPath({'sldemo_mdlref_variants/Controller', ...
'sldemo_mrv_second_order_controller/sensor1'})
bp.validate()

Validate by checking all variants. The block path passes the validation when inactive variants are also checked.

bp.validate(true)

See Also

|

Was this topic helpful?