Documentation

find_system

Find systems, blocks, lines, ports, and annotations

Syntax

Objects = find_system
Objects = find_system(System)
Objects = find_system(Name,Value)
Objects = find_system(System,Name,Value)

Description

example

Objects = find_system returns loaded systems and their blocks, including subsystems.

example

Objects = find_system(System) returns the specified system and its blocks.

example

Objects = find_system(Name,Value) returns loaded systems and the objects in those systems that meet the criteria specified by one or more Name,Value pair arguments. You can use this syntax to specify search constraints and to search for specific parameter values. Specify the search constraints before the parameter and value pairs.

example

Objects = find_system(System,Name,Value) returns the objects in the specified system that meet the specified criteria.

Input Arguments

collapse all

System to search, specified as the full system path name, a cell array of system path names, a handle, or a vector of handles.

Example: 'MyModel/Subsystem1'

Example: {'vdp','fuelsys'}

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'SearchDepth','0','LookUnderMasks','none','BlockType','Goto' searches in loaded systems, excluding masked subsystems, for Goto blocks.

When you use the find_system function, Name,Value pair arguments can include search constraints and parameter name and value pairs. You can specify search constraints in any order, but they must precede the parameter name and value pairs.

See Model Parameters and Block-Specific Parameters for the lists of model and block parameters.

The table lists the possible search constraint pairs. Braces indicate default values.

Name

Value Type

Description

'BlockDialogParams'

character vector

Search block dialog box parameters for the specified value. This pair, like parameter and value pairs, must follow the other search constraint pairs.

'CaseSensitive'

{'on'} | 'off'

If 'on', search considers case when matching.

'FindAll'

'on' | {'off'}

If 'on', search includes lines, ports, and annotations within systems. find_system returns a vector of handles when this option is set to 'on', regardless of how you specify System.

'FirstResultOnly'

'on' | {'off'}

Return only the first result found and stop the search.

'FollowLinks'

'on' | {'off'}

If 'on', search follows links into library blocks. If you do not specify a system to search, find_system includes loaded libraries in the results, whether you set 'FollowLinks' to 'on' or 'off'. You can use 'FollowLinks' with 'LookUnderMasks' to update library links in subsystems. See Update Library Links in a Subsystem.

'IncludeCommented'

'on' | {'off'}

Specify whether to include commented blocks in the search.

'LoadFullyIfNeeded'

{'on'} | 'off'

If 'on', attempts to load any partially loaded models. If 'off', disables model loading. Use this pair, for example, to prevent load warnings.

'LookUnderMasks'

{'graphical'}

Search includes masked subsystems that have no workspaces and no dialogs.

'none'

Search skips masked subsystems.

'functional'

Search includes masked subsystems that do not have dialogs.

'all'

Search includes all masked subsystems.

'on' | 'off'

If 'on', search includes all masked subsystems. If 'off', search skips masked subsystem.

'RegExp'

'on' | {'off'}

If 'on', search treats search expressions as regular expressions. To learn more about MATLAB® regular expressions, see Regular Expressions (MATLAB).

'SearchDepth'

positive integer character vector

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.

'Variants'

This search constraint applies only to variant subsystems and model variants.

{'ActiveVariants'}

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.

Output Arguments

collapse all

Matching objects found, returned as:

  • A cell array of path names if you specified System as a path name or cell array of path names, or if you did not specify a system

  • A vector of handles if you specified System as a handle or vector of handles

Examples

collapse all

Return the names of all loaded systems and their blocks.

load_system('vdp')
find_system
ans =

  13x1 cell array

    {'vdp'                     }
    {'vdp/Fcn'                 }
    {'vdp/More Info'           }
    {'vdp/More Info/Model Info'}
    {'vdp/Mu'                  }
    {'vdp/Mux'                 }
    {'vdp/Product'             }
    {'vdp/Scope'               }
    {'vdp/Sum'                 }
    {'vdp/x1'                  }
    {'vdp/x2'                  }
    {'vdp/Out1'                }
    {'vdp/Out2'                }

Returns loaded systems and libraries, including vdp.

Return vdp system and its blocks.

load_system({'vdp','fuelsys'})
find_system('vdp')
ans =

  13x1 cell array

    {'vdp'                     }
    {'vdp/Fcn'                 }
    {'vdp/More Info'           }
    {'vdp/More Info/Model Info'}
    {'vdp/Mu'                  }
    {'vdp/Mux'                 }
    {'vdp/Product'             }
    {'vdp/Scope'               }
    {'vdp/Sum'                 }
    {'vdp/x1'                  }
    {'vdp/x2'                  }
    {'vdp/Out1'                }
    {'vdp/Out2'                }

Return the names of only the loaded models, i.e., block diagrams. This command returns library names as well, because libraries are treated as models.

load_system('vdp');
open_bd = find_system('type','block_diagram')
open_bd =

  1x1 cell array

    {'vdp'}

Return the names of all Goto blocks that are children of the Unlocked subsystem in the sldemo_clutch system.

load_system('sldemo_clutch');
find_system('sldemo_clutch/Unlocked','SearchDepth',1,'BlockType','Goto')
ans =

  2x1 cell array

    {'sldemo_clutch/Unlocked/Goto' }
    {'sldemo_clutch/Unlocked/Goto1'}

Search in the vdp system and return the names of all Gain blocks whose Gain value is set to 1.

load_system('vdp');
find_system('vdp','BlockType','Gain','Gain','1')
ans =

  1x1 cell array

    {'vdp/Mu'}

Get the handles of all lines and annotations in the vdp system. With 'FindAll', the function returns handles regardless of how you specify the system to search.

load_system('vdp');
L = find_system('vdp','FindAll','on','type','line')
A = find_system('vdp','FindAll','on','type','annotation')
L =

   33.0018
   32.0018
   31.0151
   30.0209
   29.0367
   28.0017
   27.0018
   26.0023
   25.0013
   24.0018
   23.0020
   22.0017
   21.0020
   20.0016
   19.0013
   18.0020
   17.0012


A =

   35.0011
   34.0018

Find any block dialog box parameters with a value of 0 in the vdp and fuelsys systems.

load_system({'vdp','fuelsys'})
find_system({'vdp','fuelsys'},'BlockDialogParams','0')
ans = 

    'vdp/x2'
    'vdp/Out1'
    'vdp/Out2'
    'fuelsys/Constant2'
    'fuelsys/Constant4'
    'fuelsys/Constant5'
    'fuelsys/engine …'
    'fuelsys/engine …'
    'fuelsys/engine …'
    'fuelsys/engine …'
				.
				.
				.

Find all blocks in the top level of the currently loaded systems with a block dialog parameter value that starts with 3.

load_system({'fuelsys','vdp'});
find_system('SearchDepth','1','regexp','on','BlockDialogParams','^3')
ans =

  3x1 cell array

    {'vdp/Scope'         }
    {'vdp/Scope'         }
    {'fuelsys/Nominal...'}

When you search using regular expressions, you can specify a part of the character vector you want to match to return all objects that contain that character vector. Find all the inport and outport blocks in the sldemo_clutch model.

load_system('sldemo_clutch');
find_system('sldemo_clutch','regexp','on','blocktype','port')
ans =

  39x1 cell array

    {'sldemo_clutch/Friction...'                               }
    {'sldemo_clutch/Friction...'                               }
    {'sldemo_clutch/Friction...'                               }
    {'sldemo_clutch/Friction Mode Logic/Tin'                   }
    {'sldemo_clutch/Friction Mode Logic/Tfmaxs'                }
    {'sldemo_clutch/Friction Mode Logic/Break Apart...'        }
    {'sldemo_clutch/Friction Mode Logic/Break Apart...'        }
    {'sldemo_clutch/Friction Mode Logic/Break Apart...'        }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup...'             }
    {'sldemo_clutch/Friction Mode Logic/Lockup FSM/lock'       }
    {'sldemo_clutch/Friction Mode Logic/Lockup FSM/unlock'     }
    {'sldemo_clutch/Friction Mode Logic/Lockup FSM/locked'     }
    {'sldemo_clutch/Friction Mode Logic/Requisite Friction/Tin'}
    {'sldemo_clutch/Friction Mode Logic/Requisite Friction/Tf' }
    {'sldemo_clutch/Friction Mode Logic/locked'                }
    {'sldemo_clutch/Friction Mode Logic/lock'                  }
    {'sldemo_clutch/Friction Mode Logic/unlock'                }
    {'sldemo_clutch/Friction Mode Logic/Tf'                    }
    {'sldemo_clutch/Locked/Tin'                                }
    {'sldemo_clutch/Locked/w'                                  }
    {'sldemo_clutch/Unlocked/Tfmaxk'                           }
    {'sldemo_clutch/Unlocked/Tin'                              }
    {'sldemo_clutch/Unlocked/we'                               }
    {'sldemo_clutch/Unlocked/wv'                               }
    {'sldemo_clutch/we'                                        }
    {'sldemo_clutch/wv'                                        }
    {'sldemo_clutch/w'                                         }
    {'sldemo_clutch/Locked Flag'                               }
    {'sldemo_clutch/Lockup Flag'                               }
    {'sldemo_clutch/Break-Apart Flag'                          }
    {'sldemo_clutch/FrictionTorque...'                         }
    {'sldemo_clutch/Max Static...'                             }

In this example, myModel contains a single subsystem, which is a library link. After the model was last opened, a Gain block was added to the corresponding subsystem in the library.

Open the model. Use find_system with 'FollowLinks' set to 'off'. The command does not follow the library links into the subsystem and returns only the subsystem at the top level.

open_system('myModel')
find_system(bdroot,'LookUnderMasks','on','FollowLinks', 'off')
ans = 

    'myModel'
    'myModel/Subsystem'

Use find_system with 'FollowLinks' set to 'on'. find_system updates the library links and returns the block in the subsystem.

find_system(bdroot,'LookUnderMasks','on','FollowLinks','on')
Updating Link: myModel/Subsystem/Gain
Updating Link: myModel/Subsystem/Gain

ans = 

    'myModel'
    'myModel/Subsystem'
    'myModel/Subsystem/Gain'

Provide the system to find_system as a handle. Search for block dialog box parameters with a value of 0. If you make multiple calls to get_param for the same block, then using the block handle is more efficient than specifying the full block path as a character vector.

load_system('vdp');
sys = get_param('vdp','Handle');
find_system(sys,'BlockDialogParams','0')
ans =

   10.0016
   13.0016
   14.0017
   14.0017
   15.0015
   15.0015

Introduced before R2006a

Was this topic helpful?