Simulink.SimulationData.BlockPath

Fully specified Simulink block path

Description

Simulink® creates block path objects when creating dataset objects for signal logging and data store logging. Simulink.SimulationData.Signal and Simulink.SimulationData.DataStoreMemory objects include block path objects.

You can create a block path that you can use with the Simulink.SimulationData.Dataset.getElement method to access a specific dataset element. If you want to create a dataset in MATLAB to use as a baseline to compare against a signal logging or data store logging dataset, then you need to create the block paths as part of that dataset.

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

You do not have to have Simulink installed to use the Simulink.SimulationData.BlockPath class. However, you must have Simulink installed to use the Simulink.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.

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.SimulationData.BlockPath()
blockpath_object = Simulink.SimulationData.BlockPath(blockpath)
blockpath_object = Simulink.SimulationData.BlockPath(paths)
blockpath_object = Simulink.SimulationData.BlockPath(paths, subpath)

Input Arguments

blockpath

The 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

subpath

A string that represents an individual component within a block.

Output Arguments

blockpath_object

The block path that you create.

Description

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

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

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

blockpath = Simulink.SimulationData.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 a cell array of strings representing elements of the block path.

bp1 = Simulink.SimulationData.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.

bp1 = 

  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.SimulationData.BlockPath.convertToCell()

Output Arguments

cellarray

The cell array of strings representing the elements of the block path.

Description

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

Examples

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

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

cellarray_for_bp1 = 

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

getBlock

Purpose

Get single block path in model reference hierarchy

Syntax

block = Simulink.SimulationData.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.SimulationData.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.

bp1 = Simulink.SimulationData.BlockPath(...
{'sldemo_mdlref_depgraph/thermostat', ...
'sldemo_mdlref_heater/Fahrenheit to Celsius', ...
'sldemo_mdlref_F2C/Gain1'})
blockpath = bp1.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.SimulationData.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.SimulationData.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 bp1.

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

The result reflects that the block path has three elements.

length_bp1 =

     3
Was this topic helpful?