Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Resolving Symbols

About Symbol Resolution

When you create a Simulink model, you can use symbols to provide values and definitions for many types of entities in the model. Model entities that can be defined with symbols include block parameters, configuration set parameters, data types, signals, signal properties, and bus architecture.

A symbol that provides a value or definition must be a legal MATLAB identifier. Such an identifier starts with an alphabetic character, followed by alphanumeric or underscore characters up to the length given by the function namelengthmax. You can use the function isvarname to determine whether a symbol is a legal MATLAB identifier.

A symbol provides a value or definition in a Simulink model by corresponding to some item that:

The process of searching for and finding an item that corresponds to a symbol is called resolving the symbol. The matching item can provide the needed information directly, or it can itself be a symbol, which must then resolve to some other item that provides the information.

When the Simulink software compiles a model, it tries to resolve every symbol in the model, except symbols in M-code that runs in a callback or as part of mask initialization. Depending on the particular case, the item to which a symbol resolves can be a variable, object, or function.

Hierarchical Symbol Resolution

The Simulink software attempts to resolve a symbol by searching through the accessible workspaces in hierarchical order for a MATLAB variable or Simulink object whose name is the same as the symbol. The search path is identical for every symbol. The search begins with the block that uses the symbol, or is the source of a signal that is named by the symbol, and proceeds upward. Except when simulation occurs via the sim command, the search order is the following:

  1. Any mask workspaces, in order from the block upwards (see Defining Mask Parameters)

  2. The model workspace of the model that contains the block (see Using Model Workspaces)

  3. The MATLAB base workspace (See MATLAB Workspace)

If the Simulink software finds a matching item in the course of this search, the search terminates successfully at that point, and the symbol resolves to the matching item. The result is the same as if the value of that item had appeared literally instead of the symbol that resolved to the item. An object defined at a lower level shadows any object defined at a higher level.

If no matching item exists on the search path, the Simulink software attempts to evaluate the symbol as a function. If the function is defined and returns an appropriate value, the symbol resolves to whatever the function returned. Otherwise, the symbol remains unresolved, and an error occurs. Evaluation as a function occurs as the final step whenever a hierarchical search terminates without having found a matching workspace variable.

If the model that contains the symbol is a referenced model, and the search reaches the model workspace but does not succeed there, the search jumps directly to the base workspace without trying to resolve the symbol in the workspace of any parent model. Thus a given symbol will resolve to the same item irrespective of whether the model that contains the symbol is a referenced model. See Referencing a Model for information about model referencing.

Specifying Numeric Values with Symbols

Any block parameter that requires a numeric value can be specified by providing a literal value, a symbol, or an expression, which can contain symbols and literal values. Each symbol is resolved separately, as if none of the others existed. Different symbols in an expression can thus resolve to items on different workspaces, and to different types of item.

When a single symbol appears and resolves successfully, its value provides the value of the parameter. When an expression appears, and all symbols resolve successfully, the value of the expression provides the value of the parameter. If any symbol cannot be resolved, or resolves to a value of inappropriate type, an error occurs.

For example, suppose that the Gain parameter of a Gain block is given as cos(a*(b+2)). The symbol cos will resolve to the MATLAB cosine function, and a and b must resolve to numeric values, which can be obtained from the same or different types of items in the same or different workspaces. If the symbols resolve to numeric values, the value returned by the cosine function becomes the value of the Gain parameter.

Specifying Other Values with Symbols

Most symbols and expressions that use them provide numeric values, but the same techniques that provide numeric values can provide any type of value that is appropriate for its context. Another common use of symbols is to name objects that provide definitions of some kind. For example, a signal name can resolve to a signal object (Simulink.Signal) that defines the properties of the signal, and a Bus Creator block's Bus object parameter can name a bus object (Simulink.Bus) that defines the properties of the bus. Symbols can be used when defining data types, can specify input data sources and logged data destinations, and can serve many other purposes.

From the standpoint of hierarchical symbol resolution, all of these different uses of symbols, whether singly or in expressions, are the same: each symbol is resolved, if possible, independently of any others, and the result becomes available where the symbol appeared. The only difference between one symbol and another is the specific item to which the symbol resolves and the use made of that item. The only requirement is that every symbol must resolve to something that can legally appear at the location of the symbol.

Limiting Signal Resolution

Hierarchical symbol resolution traverses the complete search path by default. You can truncate the search path by using the Permit Hierarchical Resolution option of any subsystem. This option controls what happens if the search reaches that subsystem without resolving to a workspace variable. The Permit Hierarchical Resolution values are:

If the search does not find a match in the workspace, and terminates because the value is ExplicitOnly or None, the Simulink software evaluates the symbol as a function. The search succeeds or fails depending on the result of the evaluation, as previously described.

Explicit and Implicit Symbol Resolution

Models and some types of model entities have associated parameters that can affect symbol resolution. For example, suppose that a model includes a signal named Amplitude, and that a Simulink.Signal object named Amplitude exists in an accessible workspace. If the Amplitude signal's Signal name must resolve to Simulink signal object option is checked, the signal will resolve to the object. See Signal Properties Dialog Box for more information.

If the option is not checked, the signal may or may not resolve to the object, depending on the value of Configuration Parameters > Data Validity > Signal resolution. This parameter can suppress resolution to the object even though the object exists, or it can specify that resolution occurs on the basis of the name match alone. See Diagnostics Pane: Data Validity > Signal resolution for more information.

Resolution that occurs because an option like Signal name must resolve to Simulink signal object requires it is called explicit symbol resolution. Resolution that occurs on the basis of name match alone, without an explicit specification, is called implicit symbol resolution.

The MathWorks discourages using implicit symbol resolution except for fast prototyping, because implicit resolution slows performance, complicates model validation, and can have nondeterministic effects.

Programmatic Symbol Resolution

When you use the sim command to run a simulation programmatically, you have an option that does not exist with interactive simulation: you can specify a workspace other than the MATLAB base workspace as the last workspace searched in hierarchical symbol resolution.

Most simulation is interactive, so most Simulink documentation does not mention this possibility. For information about substituting another workspace for the base workspace during programmatic simulation, see the sim command reference page.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS