Using Simulink     Search    Help Desk 

Initialization Commands

Initialization commands define variables that reside in the mask workspace. These variables can be used by all initialization commands defined for the mask, by blocks in the masked subsystem, and by commands that draw the block icon (drawing commands).

Simulink executes the initialization commands when:

Initialization commands are valid MATLAB expressions, consisting of MATLAB functions, operators, and variables defined in the mask workspace. Initialization commands cannot access base workspace variables. Terminate initialization commands with a semicolon to avoid echoing results to the command window.

The Mask Workspace

Simulink creates a local workspace, called a mask workspace, when either of the following occurs:

Masked blocks cannot access the base workspace or other mask workspaces.

The contents of a mask workspace include the variables associated with the mask's parameters and variables defined by initialization commands. The variables in the mask workspace can be accessed by the masked block. If the block is a subsystem, they can also be accessed by all blocks in the subsystem.

Mask workspaces are analogous to the local workspaces used by M-file functions. You can think of the expressions entered into the dialog boxes of the underlying blocks and the initialization commands entered on the Mask Editor as lines of an M-file function. Using this analogy, the local workspace for this "function" is the mask workspace.

In the mx + b example, described earlier in this chapter, the Mask Editor explicitly creates m and b in the mask workspace by associating a variable with a mask parameter. However, variables in the mask workspace are not explicitly assigned to blocks underneath the mask. Instead, blocks beneath the mask have access to all variables in the mask workspace. It may be instructive to think of the underlying blocks as "looking into" the mask workspace.

The figure below shows the mapping of values entered in the mask dialog box to variables in the mask workspace (indicated by the solid line) and the access of those variables by the underlying blocks (indicated by the dashed line).


Debugging Initialization Commands

You can debug initialization commands in these ways:



[ Previous | Help Desk | Next ]