Documentation

find_system

Find systems, blocks, lines, ports, and annotations

Syntax

find_system(sys, 'c1', cv1, 'c2', cv2,...'p1', v1, 'p2', v2,...)

Description

find_system(sys, 'c1', cv1, 'c2', cv2,...'p1', v1, 'p2', v2,...) searches the loaded systems or subsystems specified by sys, using the constraints c1, c2 etc., with values cv1, cv2, etc., and returns handles or paths to the objects whose parameters, p1, p2, etc., have the values v1, v2, etc. The sys argument 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.

    Note   All the search constraints must precede all the parameter-value pairs in the argument list.

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 loaded 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 Parameters and Block-Specific 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 loaded 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.

'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. Use to search for partial matches. The default is'off'.

See Searching with Regular Expressions.

'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.

'IncludeCommented'

'on' | {'off'}

Specify whether to include commented blocks in the search.

The table indicates default constraint values in brackets. If you omit a 'constraint', find_system uses the default constraint value.

Examples

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

find_system

This command returns the names of all loaded 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 sldemo_clutch system.

sldemo_clutch
find_system('sldemo_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.

vdp
gb = find_system('vdp', 'BlockType', 'Gain')
find_system(gb, 'Gain', '1')

The preceding two commands are equivalent to this command:

vdp
find_system('vdp', 'BlockType', 'Gain', 'Gain', '1')

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

vdp
sys = get_param('vdp', 'Handle');
l = find_system(sys, 'FindAll', 'on', 'type', 'line');
a = find_system(sys, 'FindAll', 'on', 'type', 
'annotation');

Turn off the LoadFullyIfNeeded search constraint.

find_system(gcs,'LoadFullyIfNeeded','off','ParameterName','ParameterValue')

Search for partial matches for X within any block dialog parameter value:

find_system('Regexp', 'on', 'BlockDialogParams','X')

Searching for Blocks with a Specific Tag

Use the block Tag property to search for blocks.

  1. Open the vdp model.

    open_system(‘vdp')
  2. Right-click the Sum block, and from the menu, select Properties. The Block Properties: Sum dialog opens.

  3. In the Tag box, enter sum blocks, and then click OK.

  4. Search for the tag sum blocks.

    find_system('vdp', 'Tag', 'sum blocks')
    ans = 
        'vdp/Sum'

Searching Block Dialog Parameter Values

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')

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 details, see Regular Expressions.

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 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 sldemo_clutch model that is provided with Simulink software.

sldemo_clutch
find_system('sldemo_clutch', 'regexp', 'on', 'blocktype', 'port')
Was this topic helpful?