Mask Editor

www.kxcad.net Home > CAE Software Index > MATLAB Index >


Your Ad Here

Creating a Subsystem Mask

A Mask Editor like the following appears in either case.

The Mask Editor contains a set of tabbed panes, each of which enables you to define a feature of the mask:

Five buttons appear along the bottom of the Mask Editor:

To see the system under the mask without unmasking it, select the Subsystem block, then select Look Under Mask from the Edit menu. This command opens the subsystem. The block's mask is not affected.

Icon Pane

The Mask Editor's Icon pane enables you to create icons that can contain descriptive text, state equations, images, and graphics.

The Icon pane contains the following controls.

Drawing commands

This field allows you to enter commands that draw the block's icon. Simulink provides a set of commands that can display text, one or more plots, or show a transfer function (see Mask Icon Drawing Commands). You must use only these commands to draw your icon. Simulink executes the drawing commands in the order in which they appear in this field. Drawing commands have access to all variables in the mask workspace. If Simulink cannot successfully execute the drawing commands, the icon displays three question marks.

This example demonstrates how to create an improved icon for the mx + b sample masked subsystem discussed earlier in this section. First you must enter the following initialization commands to define the data that enables the drawing command to produce an accurate icon regardless of the shape of the block:

pos = get_param(gcb, 'Position');
width = pos(3) - pos(1); height = pos(4) - pos(2);
x = [0, width];
if (m >= 0), y = [0, (m*width)]; end
if (m < 0),  y = [height, (height + (m*width))]; end

The drawing command that generates this icon is plot(x,y).

Simulink executes the drawing commands when you

Examples of drawing commands

This panel illustrates the usage of the various icon drawing commands supported by Simulink. To determine the syntax of a command, select the command from the Command list. Simulink displays an example of the selected command at the bottom of the panel and the icon produced by the command to the right of the list.

Icon options

These controls allow you to specify the following attributes of the block icon.

Frame.   The icon frame is the rectangle that encloses the block. You can choose to show or hide the frame by setting the Frame parameter to Visible or Invisible. The default is to make the icon frame visible. For example, this figure shows visible and invisible icon frames for an AND gate block.

Transparency.   The icon can be set to Opaque or Transparent, either hiding or showing what is underneath the icon. Opaque, the default, covers information Simulink draws, such as port labels. This figure shows opaque and transparent icons for an AND gate block. Notice the text on the transparent icon.

Rotation.   When the block is rotated or flipped, you can choose whether to rotate or flip the icon or to have it remain fixed in its original orientation. The default is not to rotate the icon. The icon rotation is consistent with block port rotation. This figure shows the results of choosing Fixed and Rotates icon rotation when the AND gate block is rotated.

Units.   This option controls the coordinate system used by the drawing commands. It applies only to plot and text drawing commands. You can select from among these choices: Autoscale, Normalized, and Pixel.

Parameters Pane

The Parameters pane allows you to create and modify masked subsystem parameters (mask parameters, for short) that determine the behavior of the masked subsystem.

The Parameters pane contains the following elements:

Dialog Parameters Panel

Lists the mask's parameters in tabular form. Each row displays the major attributes of one of the mask's parameters.

Prompt.   Text that identifies the parameter on a masked subsystem's dialog box.

Variable.   Name of the variable that stores the parameter's value in the mask's workspace (see Mask Workspace). You can use this variable as the value of parameters of blocks inside the masked subsystem, thereby allowing the user to set the parameters via the mask dialog box.

Type.   Type of control used to edit the value of this parameter. The control appears on the mask's parameter dialog box following the parameter prompt. The button that follows the type name in the Parameters pane pops up a list of the controls supported by Simulink (see Control Types). To change the current control type, select another type from the list.

Evaluate.   If checked, this option causes Simulink to evaluate the expression entered by the user before it is assigned to the variable. Otherwise, Simulink treats the expression itself as a string value and assigns it to the variable. For example, if the user enters the expression gain in an edit field and the Evaluate option is checked, Simulink evaluates gain and assigns the result to the variable. Otherwise, Simulink assigns the string 'gain' to the variable. See Check Box Control and Pop-Up Control for information on how this option affects evaluation of the parameters.

If you need both the string entered and the evaluated value, clear the Evaluate option. To get the value of a base workspace variable entered as the literal value of the mask parameter, use the MATLAB evalin command in the mask initialization code. For example, suppose the user enters the string 'gain' as the literal value of the mask parameter k where gain is the name of a base workspace variable. To obtain the value of the base workspace variable, use the following command in the mask's initialization code:

value = evalin('base', k)

Tunable.   Selecting this option allows a user to change the value of the mask parameter while a simulation is running.

Options for Selected Parameter Panel

This panel allows you to set additional options for the parameter selected in the Dialog parameters table.

Show parameter.   The selected parameter appears on the masked block's parameter dialog box only if this option is checked (the default).

Enable parameter.   Clearing this option grays the selected parameter's prompt and disables its edit control. This means that the user cannot set the value of the parameter.

Popups.   This field is enabled only if the edit control for the selected parameter is a pop-up. Enter the values of the pop-up control in this field, each on a separate line.

Callback.   Enter MATLAB code that you want Simulink to execute when a user applies a change to the selected parameter, i.e., selects the Apply or OK button on the mask dialog box. You can use such callbacks to create dynamic dialogs, i.e., dialogs whose appearance changes, depending on changes to control settings made by the user, e.g., enabling an edit field when a user checks a check box (see Creating Dynamic Mask Parameter Dialog Boxes more information).

The callback can create and reference variables only in the block's base workspace. If the callback needs the value of a mask parameter, it can use get_param to obtain the value, e.g.,

if str2num(get_param(gcb, 'g'))<0
	error('Gain is negative.')
end

Simulink executes the callback commands when you

For information on debugging dialog callbacks, see Debugging Masks.

Parameter Buttons

The following sections explain the purpose of the buttons that appear on the Parameters pane in the order of their appearance from the top of the pane.

Add Button.   Adds a parameter to the mask's parameter list. The newly created parameter appears in the adjacent Dialog parameters table.

Delete Button.   Deletes the parameter currently selected in the Dialog parameters table.

Up Button.   Moves the currently selected parameter up one row in the Dialog parameters table. Dialog parameters appear in the mask's parameter dialog box (see Mask Parameter Dialog Box) in the same order in which they appear in the Dialog parameters table. This button (and the next) thus allows you to determine the order in which parameters appear on the dialog box.

Down Button.   Moves the currently selected parameter down one row in the Dialog parameters table and hence down one position on the mask's parameter dialog box.

Control Types

Simulink enables you to choose how parameter values are entered or selected. You can create three styles of controls: edit fields, check boxes, and pop-up controls. For example, this figure shows the parameter area of a mask dialog box that uses all three styles of controls (with the pop-up control open).

Edit Control

An edit field enables the user to enter a parameter value by typing it into a field. This figure shows how the prompt for the sample edit control was defined.

The value of the variable associated with the parameter is determined by the Evaluate option.

EvaluateValue

On

The result of evaluating the expression entered in the field

Off

The actual string entered in the field

Check Box Control

A check box enables the user to choose between two alternatives by selecting or deselecting a check box. This figure shows how the sample check box control is defined.

The value of the variable associated with the parameter depends on whether the Evaluate option is selected.

Control StateEvaluated ValueLiteral Value

Selected

1

'on'

Unselected

0

'off'

Pop-Up Control

A pop-up enables the user to choose a parameter value from a list of possible values. Specify the values in the Popups field on the Options for selected parameter pane (see Popups). The following example shows a pop-up parameter.

The value of the variable associated with the parameter (Color) depends on the item selected from the pop-up list and whether the Evaluate option is checked (on).

EvaluateValue
OnIndex of the value selected from the list, starting with 1. For example, if the third item is selected, the parameter value is 3.
OffString that is the value selected. If the third item is selected, the parameter value is 'green'.

Initialization Pane

The Initialization pane allows you to enter MATLAB commands that initialize the masked subsystem.

Simulink executes the initialization commands when you

The Initialization pane includes the following controls.

Dialog variables

The Dialog variables list displays the names of the variables associated with the subsystem's mask parameters, i.e., the parameters defined in the Parameters pane. You can copy the name of a parameter from this list and paste it into the adjacent Initialization commands field, using the Simulink keyboard copy and paste commands. You can also use the list to change the names of mask parameter variables. To change a name, double-click the name in the list. An edit field containing the existing name appears. Edit the existing name and press Enter or click outside the edit field to confirm your changes.

Initialization commands

Enter the initialization commands in this field. You can enter any valid MATLAB expression, consisting of MATLAB functions and scripts, 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. For information on debugging initialization commands, see Debugging Masks.

Allow library block to modify its contents

This check box is enabled only if the masked subsystem resides in a library. Checking this option allows the block's initialization code to modify the contents of the masked subsystem, i.e., it lets the code add or delete blocks and set the parameters of those blocks. Otherwise, Simulink generates an error when a masked library block tries to modify its contents in any way. To set this option at the MATLAB prompt, select the self-modifying block and enter the following command.

set_param(gcb, 'MaskSelfModifiable', 'on');

Then save the block.

Initialization Command Limitations

Mask initialization commands must observe the following rules:

Documentation Pane

The Documentation pane enables you to define or modify the type, description, and help text for a masked block.

This figure shows how fields on the Documentation pane correspond to the mx + b sample mask block's dialog box.

Mask Type Field

The mask type is a block classification used only for purposes of documentation. It appears in the block's dialog box and on all Mask Editor panes for the block. You can choose any name you want for the mask type. When Simulink creates the block's dialog box, it adds "(mask)" after the mask type to differentiate masked blocks from built-in blocks.

Mask Description Field

The block description is informative text that appears in the block's dialog box in the frame under the mask type. If you are designing a system for others to use, this is a good place to describe the block's purpose or function.

Simulink automatically wraps long lines of text. You can force line breaks by using the Enter or Return key.

Block Help Field

You can provide help text that is displayed when the Help button is clicked on the masked block's dialog box. If you create models for others to use, this is a good place to explain how the block works and how to enter its parameters.

You can include user-written documentation for a masked block's help. You can specify any of the following for the masked block help text:

Simulink examines the first line of the masked block help text. If Simulink detects a URL specification, for example,

http://www.mathworks.com

or

file:///c:/mydir/helpdoc.html

Simulink displays the specified file in the browser. If Simulink detects a web command, for example,

web([docroot '/My Blockset Doc/' get_param(gcb,'MaskType')... 
'.html'])

or an eval command, for example,

eval('!Word My_Spec.doc')

Simulink executes the specified command. Otherwise, Simulink displays the contents of the Block Help field, which can include HTML tags, in the browser.

Note, if you enter HTML-tagged text, Simulink copies that text into a temporary directory and displays it from that temporary directory. If you want to include an image (for example, with the img tag) with that text, you need to place the image file in that temporary directory. (You can use tempdir to find the temporary directory for your system.) Alternatively, you can save the HTML-tagged text into an HTML file (such as hello.html) in the current directory and display that file directly (for example, web('hello.html', '-helpbrowser')). This method enables you to place referenced image files in the same directory as the HTML file.

  


© 1984-2007 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments

Your Ad Here