Simulink Reference    
find_system

Find systems, blocks, lines, ports, and annotations.

Syntax

Description

find_system(sys, 'c1', cv1, 'c2', cv2,...'p1', v1, 'p2', v2,...) searches the systems or subsystems specified by sys, using the constraints specified by c1, c2, etc., and returns handles or paths to the objects having the specified parameter values v1, v2, etc. sys can be a pathname (or cell array of pathnames), a handle (or vector of handles), or omitted. If sys is a pathname or cell array of pathnames, find_system returns a cell array of pathnames of the objects it finds. If sys is a handle or a vector of handles, find_system returns a vector of handles to the objects that it finds. If sys is omitted, find_system searches all open systems and returns a cell array of pathnames.

Case is ignored for parameter names. Value strings are case sensitive by default (see the 'CaseSensitive' search constraint for more information). Any parameters that correspond to dialog box entries have string values. See Appendix , "Model and Block Parameters, for a list of model and block parameters.

You can specify any of the following search constraints.

Name
Value Type
Description
'SearchDepth'
scalar
Restricts the search depth to the specified level (0 for open systems only, 1 for blocks and subsystems of the top-level system, 2 for the top-level system and its children, etc.). The default is all levels.
'LookUnderMasks'
'none'
Search skips masked blocks.

{'graphical'}
Search includes masked blocks that have no workspaces and no dialogs. This is the default.

'functional'
Search includes masked blocks that do not have dialogs.

'all'
Search includes all masked blocks.
'FollowLinks'
'on'| {'off'}
If 'on', search follows links into library blocks. The default is 'off'.
'FindAll'
'on'| {'off'}
If 'on', search extends to lines, ports, and annotations within systems. The default is 'off'. Note that find_system returns a vector of handles when this option is 'on', regardless of the array type of sys.
'CaseSensitive'
{'on'}| 'off'

If 'on', search considers case when matching search strings. The default is 'on'.
'RegExp'
'on'| {'off'}

If 'on', search treats search expressions as regular expressions. The default is 'off'.

The table encloses default constraint values in brackets. If a 'constraint' is omitted, find_system uses the default constraint value.

Examples

This command returns a cell array containing the names of all open systems and blocks.

This command returns the names of all open block diagrams.

This command returns the names of all Goto blocks that are children of the Unlocked subsystem in the clutch system.

These commands return the names of all Gain blocks in the vdp system having a Gain parameter value of 1.

The preceding commands are equivalent to this command:

These commands obtain the handles of all lines and annotations in the vdp system.

Searching with Regular Expressions

If you specify the 'RegExp'constraint as 'on', find_system treats search value strings as regular expressions. A regular expression is a string of characters in which some characters have special pattern-matching significance. For example, a period (.) in a regular expression matches not only itself but any other character.

Regular expressions greatly expand the types of searches you can perform with find_system. For example, regular expressions allow you to do partial word searches. You can search for all objects that have a specified parameter that contains or begins or ends with a specified string of characters.

To use regular expressions effectively, you need to learn the meanings of the special characters that regular expressions can contain. The following table lists the special characters supported by find_subystem and explains their usage.

Expression
Usage
.
Matches any character. For example, the string 'a.' matches 'aa', 'ab', 'ac', etc.
*
Matches zero or more of preceding character. For example, 'ab*' matches 'a', 'ab', 'abb', etc. The expression '.*' matches any string, including the empty string.
+
Matches one or more of preceding character. For example, 'ab+' matches 'ab', 'abb', etc.
^
Matches start of string. For example, '^a.*' matches any string that starts with 'a'.
$
Matches end of string. For example, '.*a$' matches any string that ends with 'a'.
\
Causes the next character to be treated as an ordinary character. This escape character lets regular expressions match expressions that contain special characters. For example, the search string '\\' matches any string containing a \ character.
[]
Matches any one of a specified set of characters. For example, 'f[oa]r' matches 'for' and 'far'. Some characters have special meaning within brackets. A hyphen (-) indicates a range of characters to match. For example, '[a-zA-Z1-9]' matches any alphanumeric character. A circumflex (^) indicates characters that should not produce a match. For example, 'f[^i]r' matches 'far' and 'for' but not 'fir'.
\w
Matches a word character. (This is a shorthand expression for [a-z_A-Z0-9].) For example, '^\w' matches 'mu' but not '&mu'.
\d
Matches any digit (shorthand for [0-9]). For example, '\d+' matches any integer.
\D
Matches any nondigit (shorthand for [^0-9]).
\s
Matches a white space (shorthand for [ \t\r\n\f]).
\S
Matches a non-white-space (shorthand for [^ \t\r\n\f]).
\<WORD\>
Matches WORD exactly, where WORD is a string of characters separated by white space from other words. For example, '\<to\>' matches 'to' but not 'today'.

To use regular expressions to search Simulink systems, specify the 'regexp' search constraint as 'on' in a find_system command and use a regular expression anywhere you would use an ordinary search value string.

For example, the following command finds all the inport and outport blocks in the clutch model demo provided with Simulink.

See Also


  delete_param gcb