find

Specified objects in hierarchy

Description

example

objArray = thisObject.find(Name,Value) returns an array of objects in the hierarchy of thisObject that match the criteria specified by one or more Name,Value pair arguments.

example

objArray = thisObject.find('-not',Name,Value) returns objects that do not match the criteria specified by the subsequent Name,Value pair argument.

example

objArray = thisObject.find('-regexp',Name,Value) indicates that the subsequent Name,Value pair argument contains a regular expression. For more information, see Regular Expressions.

example

objArray = thisObject.find(___,logicalOp,___) combines search criteria by using one of these logical operations:

  • '-and' — Results must match both search criteria.

  • '-or' — Results must match at least one criterion.

  • '-xor' — Results must match exactly one criterion.

When using various logical operators, -and has the highest precedence, while -or and -xor are right-associative. If no logical operator is specified, then -and is assumed.

Input Arguments

expand all

Name-Value Pair Arguments

Example: ch.find('Name','A') finds all objects in the chart ch whose Name property is 'A'.

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. In addition to the Name,Value arguments listed here, you can use the name of a Stateflow® API property and its corresponding value. For more information, see Properties and Methods Sorted By Application.

Type of object for which to search, specified as the comma-separated pair consisting of '-isa' and a character vector or a handle to the class.

Example: ch.find('-isa','Stateflow.State') finds all states in the chart ch.

Example: ch.find('-isa',object.classhandle) finds all objects that have the same class as object.

Depth of search in the object hierarchy, specified as the comma-separated pair consisting of '-depth' and a scalar nonnegative integer or inf.

Example: ch.find('-depth',2) finds all objects in the top two levels of the hierarchy of the chart ch.

Filtering function, specified as the comma-separated pair consisting of '-function' and a function handle. The function evaluates each object visited in the search and returns a logical scalar value that indicates whether the object is a match.

Example: ch.find('-function',f) finds all objects for which f is true.

Method that belongs to the objects for which to search, specified as the comma-separated pair consisting of '-method' and a character vector.

Example: ch.find('-method','dialog') finds all objects in the chart ch that have a method called dialog.

Property that belongs to the objects for which to search, specified as the comma-separated pair consisting of '-property' and a character vector.

Example: ch.find('-property','HasOutputData') finds all objects in the chart ch that have a property called HasOutputData.

Examples

expand all

Find all states in the chart ch.

states = ch.find('-isa','Stateflow.State')

Find all states in the chart ch whose Name property is 'A'.

statesNamedA = ch.find('-isa','Stateflow.State','-and','Name','A')

Find all objects in the chart ch whose Name property starts with the letter A.

startsWithA = c.find('-regexp','Name','^A')

Find all objects in the chart ch that do not have a method called fitToView.

nongraphical = ch.find('-not','-method','fitToView')

Find all charts in a Simulink® model called myModel.

f = @(h) (strcmp(h.Machine.Name,'myModel'));                   % define function handle
ch = rt.find('-isa','Stateflow.Chart','-and','-function',f);   % find charts for which f returns 'true'

Tips

  • Using the find method for Root or Machine objects can return Simulink objects that match the search criteria you specify. For example, this command can return a Simulink subsystem or block named ABC:

    rt.find('Name','ABC')

  • Opening a main model that refers to a linked Stateflow chart does not guarantee that the Stateflow API can find the linked chart. To access the objects in a linked library chart, first load the library model into the Simulink workspace by performing one of these tasks:

    • Open the library model.

    • View a linked subsystem or block in the main model.

    • Compile or simulate the model.

Introduced before R2006a