Skip to Main Content Skip to Search
Product Documentation

Simulink.findVars - Returns information about workspace variables used or not used by models and blocks.

Syntax

[VarsOut] = Simulink.findVars (context)
[VarsOut] = Simulink.findVars (context, Options, VarProps)
[VarsOut] = Simulink.findVars (context, VarsIn, Options, VarProps)

Description

[VarsOut] = Simulink.findVars (context) returns one or more Simulink.WorkspaceVar objects. Each object describes a workspace variable used by context, which is the name of a model, the name of a block (possibly masked) specified as modelname/blockname, or a cell array of model and/or block names. The search for variables includes all subsystems and referenced models in context. The returned VarsOut includes an object for every variable referenced directly or indirectly by context, except as noted in the Limitations below.

[VarsOut] = Simulink.findVars (context, Options, VarProps) searches context as specified by Options and includes in VarsOut only Simulink.WorkspaceVar objects that satisfy the Options and match the specification(s) in VarProps. See Input Arguments for more information.

[VarsOut] = Simulink.findVars (context, VarsIn, Options, VarProps) limits the results to the variables specified in VarsIn, where VarsIn may be a Simulink.WorkspaceVar object or an array of Simulink.WorkspaceVar objects.

Input Arguments

context

The name of a model, the name of a block specified as modelname/blockname, or a cell array containing any number of model names and/or block names.

Options

Specifications that control the search for variables. You can omit any or all Options. The possible Options are:

  • 'SearchMethod', SearchType

    Searches context using the search technique specified by SearchType, which can be one of the following:

    • 'compiled' — Compile every model involved in the search before searching. Data returned from this search is guaranteed to be up to date.

    • 'cached' — Do not compile any models, just search the results cached by the previous compilation (diagram update). This technique is faster but may return outdated information.

    Default: 'compiled'

  • 'RegExp', 'on' or 'off'

    Enables or disables the use of regular expressions in VarProps. See Regular Expressions for more information.

    Default: 'off' — Do not enable regular expressions.

  • 'FindUsedVars', boolean

    Finds used or unused workspace variables in a given block or model context. If the context is a model, it should be open.

    • true — Find used variables in the given context.

    • false — Find unused variables in the given context.

    Default: true

VarProps

One or more fieldname/value pairs used to filter the results. Only Simulink.WorkspaceVar objects in which the field called fieldname has the value value appear in the output argument list VarsOut. A fieldname can be:

  • Name — The name of the variable represented by the Simulink.WorkspaceVar object.

  • Workspace — The name of the workspace that contains the variable represented by the Simulink.WorkspaceVar object.

  • WorkspaceType — The type of the workspace that contains the variable represented by the Simulink.WorkspaceVar object.

  • UsedByBlocks — The names of the blocks that use the variable represented by the Simulink.WorkspaceVar object.

Default: Return all Simulink.WorkspaceVar objects, subject to the specifications in Options, that match whatever VarProps specifications are provided. Omitting a VarProps pair effectively wildcards that Simulink.WorkspaceVar field value.

Output Arguments

VarsOut

A vector containing zero or more Simulink.WorkspaceVar objects. Each element describes a workspace variable that meets the criteria defined by the input arguments. The vector is empty if no variables match the specifications.

Examples

Find all variables that MyModel uses, recompiling first:

[VarsOut]=Simulink.findVars('MyModel')
 

Find all uses of the base workspace variable k by MyModel without recompiling the model:

[VarsOut]=Simulink.findVars('MyModel', 'Name', 'k', 'SearchMethod', 'cached', 'WorkspaceType', 'base')
 

Find in any workspace any uses of a variable whose names match a regular expression:

[VarsOut]=Simulink.findVars('MyModel',  'Regexp', 'on', 'Name', '^trans')
 

Given two models, discover which variables are needed by the first model, the second model, or both models:

model1Vars = Simulink.findVars('model1');
model2Vars = Simulink.findVars('model2');
commonVars = intersect(model1vars, model2Vars);
 

Locate all variables in the base workspace that are not being used by MyModel:

unusedVars = Simulink.findVars('MyModel', 'FindUsedVars', false, 'WorkspaceType', 'base');
 

Determine if the base workspace variable k is not used by MyModel:

varObj = Simulink.WorkspaceVar('k', 'base workspace');
unusedVar = Simulink.findVars('MyModel', varObj, 'FindUsedVars', false);
 

Find the variables that are used by the Gain1 block in MyModel:

[VarsOut] = Simulink.findVars('MyModel', 'UsedByBlocks', 'MyModel/Gain1');

Limitations

Simulink.findVars does not work with the following constructs:

See Also

find_system | intersect | Simulink.WorkspaceVar

  


Related Products & Applications

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