Masked Subsystem Example

Introduction to Example

This simple subsystem (masking_example) models the equation for a line, y = mx + b.

Ordinarily, when you double-click a Subsystem block, the Subsystem block opens, displaying its blocks in a separate window. The mx + b subsystem contains a Gain block, named Slope, whose Gain parameter is specified as m, and a Constant block, named Intercept, whose Constant value parameter is specified as b. These parameters represent the slope and intercept of a line.

This example creates a custom dialog box and icon for the subsystem. One dialog box contains prompts for both the slope and the intercept.

After you create the mask, double-click the Subsystem block to open the mask dialog box. The mask dialog box and icon look like this:

A user enters values for Slope and Intercept in the mask dialog box. These values are available to all the blocks in the underlying subsystem. Masking this subsystem creates a self-contained functional unit with its own application-specific parameters, Slope and Intercept. The mask maps these mask parameters to the generic parameters of the underlying blocks. The complexity of the subsystem is encapsulated by a new interface that has the look and feel of a built-in MATLAB® block.

To create a mask for this subsystem, you need to

Creating Mask Dialog Box Prompts

To create the mask for this subsystem, select the Subsystem block and choose Mask Subsystem from the Edit menu.

This example primarily uses the Mask Editor's Parameters pane to create the masked subsystem's dialog box (see Parameters Pane).

The Mask Editor enables you to specify these attributes of a mask parameter:

Generally, it is convenient to refer to masked parameters by their prompts. In this example, the parameter associated with slope is referred to as the Slope parameter, and the parameter associated with intercept is referred to as the Intercept parameter.

The slope and intercept are defined as edit controls. This means that the user types values into edit fields in the mask dialog box. These values are stored in variables in the mask workspace. A masked block can access variables in its mask workspace. In this example, the value entered for the slope is assigned to the variable m. The Slope block in the masked subsystem gets the value for the slope parameter from the mask workspace.

This figure shows how the slope parameter definitions in the Mask Editor map to the actual mask dialog box parameters.

After you create the mask parameters for slope and intercept, click OK. Then double-click the Subsystem block to open the newly constructed dialog box. Enter 3 for the Slope and 2 for the Intercept parameter.

Creating the Block Description and Help Text

The mask type, block description, and help text are defined on the Documentation pane (see Documentation Pane). For this sample masked block, the pane looks like this.

Creating the Block Icon

So far, we have created a customized dialog box for the mx + b subsystem. However, the Subsystem block still displays the generic Simulink® subsystem icon. An appropriate icon for this masked block is a plot that indicates the slope of the line. For a slope of 3, that icon looks like this.

The block icon is defined on the Icon pane. For this block, the Icon pane looks like this.

The drawing command

plot([0 1],[0 m]+(m<0))

plots a line from (0,0) to (1,m). If the slope is negative, the line is shifted up by 1 to keep it within the visible drawing area of the block.

The drawing commands have access to all the variables in the mask workspace. As you enter different values of slope, the icon updates the slope of the plotted line.

Select Normalized as the Drawing coordinates parameter, located at the bottom of the list of icon properties, to specify that the icon be drawn in a frame whose bottom-left corner is (0,0) and whose top-right corner is (1,1). See Icon Pane for more information.

  


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