| Contents | Index |
find_system(sys, 'c1', cv1, 'c2', cv2,...'p1', v1, 'p2', v2,...)
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 whose parameters, p1, p2, etc., have the values, v1, v2, etc. sys can be a pathname (or cell array of pathnames), a handle (or vector of handles), or omitted. To search block dialog parameter values, specify 'BlockDialogParams' as the parameter name.
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 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 subsystems. |
{'graphical'} | Search includes masked subsystems that have no workspaces and no dialogs. This is the default. | |
'functional' | Search includes masked subsystems that do not have dialogs. | |
'all' | Search includes all masked subsystems. | |
'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. |
{'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. Use to search for partial matches. The default is'off'. |
'LoadFullyIfNeeded' | {'on'}| 'off' | If 'on', attempts to load any partially loaded models. The default is'on'. If 'off', disables the model loading, for example to prevent load warnings. |
'Variants' | {'ActiveVariants'} | (Default) Search in only the active variant subsystems. |
'AllVariants' | Search in all variants. | |
'ActivePlusCodeVariants' | Search all variants if any generate preprocessor conditionals. Otherwise, search only the active variant. |
The table indicates default constraint values in brackets. If you omit a 'constraint', find_system uses the default constraint value.
This command returns a cell array containing the names of all open systems and blocks.
find_system
This command returns the names of all open block diagrams.
open_bd = find_system('type', 'block_diagram')
This command returns the names of all Goto blocks that are children of the Unlocked subsystem in the clutch system.
find_system('clutch/
Unlocked','SearchDepth',1,'BlockType','Goto')
These commands return the names of all Gain blocks in the vdp system having a Gain parameter value of 1.
gb = find_system('vdp', 'BlockType', 'Gain')
find_system(gb, 'Gain', '1')
The preceding commands are equivalent to this command:
find_system('vdp', 'BlockType', 'Gain', 'Gain', '1')
These commands obtain the handles of all lines and annotations in the vdp system.
sys = get_param('vdp', 'Handle');
l = find_system(sys, 'FindAll', 'on', 'type', 'line');
a = find_system(sys, 'FindAll', 'on', 'type',
'annotation');
This command turns off the LoadFullyIfNeeded search constraint.
find_system(gcs,'LoadFullyIfNeeded','off','ParameterName','ParameterValue')
This command searches for partial matches for X within any block dialog parameter value:
find_system('Regexp', 'on', 'BlockDialogParams','X')Use the parameter 'BlockDialogParams' to search block dialog parameter values. For example, to find any block which has a dialog parameter whose value is the string 'X+1', enter:
find_system('BlockDialogParams','X+1')
To find any partial matches within parameter values, for any find_system command, first specify the option 'Regexp', 'on'. For the example above, to find X within the parameter value 'X+1', enter:
find_system('Regexp', 'on', 'BlockDialogParams','X')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_system 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 software.
find_system('clutch', 'regexp', 'on', 'blocktype', 'port')

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |