Main Content

find

Specified objects in hierarchy

Description

example

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

example

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

example

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

example

objArray = find(location,___,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.

Examples

collapse all

Find all states in the chart ch.

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

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

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

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

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

Find all objects in the chart ch that do not have an object function called fitToView.

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

Find all charts in a Simulink® model called myModel.

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

Input Arguments

collapse all

Name-Value Pair Arguments

Example: find(ch,'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 List of Stateflow API Properties.

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

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

Example: find(ch,'-isa',classhandle(object)) finds all objects that have the same class handle 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: find(ch,'-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: find(ch,'-function',f) finds all objects for which f is true.

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

Example: find(ch,'-method','dialog') finds all objects in the chart ch that have an object function 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: find(ch,'-property','HasOutputData') finds all objects in the chart ch that have a property called HasOutputData.

Output Arguments

collapse all

Search results, returned as an array of Stateflow API objects.

Tips

  • Using the find function on Simulink.Root or Stateflow.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:

    find(rt,'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