Annotating Diagrams

How to Annotate Diagrams

Annotations provide textual information about a model. You can add an annotation to any unoccupied area of your block diagram.

To create a model annotation, double-click an unoccupied area of the block diagram. A small rectangle appears and the cursor changes to an insertion point. Start typing the annotation contents. Each line is centered in the rectangle that surrounds the annotation.

To move an annotation, drag it to a new location.

To edit an annotation, select it:

To delete an annotation, hold down the Shift key while you select the annotation, then press the Delete or Backspace key.

To change an annotation's font, select the annotation, then choose Font from the Format menu. Select a font and size from the dialog box.

To change the text alignment (e.g., left, center, or right) of the annotation, select the annotation and choose Text Alignment from model editor's Format or the context menu. Then choose one of the alignment options (e.g., Center) from the Text Alignment submenu.

Annotations Properties Dialog Box

The Annotation Properties dialog box allows you to specify the contents and format of the currently selected annotation and to associate a click function with the annotation.

To display the Annotation Properties dialog box for an annotation, select the annotation and then select Annotation Properties from model editor's Edit or the context menu.

The dialog box appears.

The dialog box includes the following controls.

Text

Displays the current text of the annotation. Edit this field to change the annotation text.

Drop shadow

Checking this option causes a drop shadow to be displayed around the annotation, giving it a 3-D appearance.

Enable TeX commands

Checking this option enables use of TeX formatting commands in this annotation. See Using TeX Formatting Commands in Annotations for more information.

Font

Clicking this button displays a font chooser dialog box. Use the font chooser to change the font used to render the annotation's text.

Foreground color

Specifies the color of the annotation text.

Background color

Specifies the color of the background of the annotation's bounding box.

Alignment

Specifies the alignment of the annotation's text relative to its bounding box.

ClickFcn

Specifies MATLAB code to be executed when a user single-clicks this annotation. The Simulink software stores the code entered in this field with the model. See Associating Click Functions with Annotations for more information.

Use display text as click callback

Checking this option causes the text in the Text field to be treated as the annotation's click function. The specified text must be a valid MATLAB expression comprising symbols that are defined in the MATLAB workspace when the user clicks this annotation. See Associating Click Functions with Annotations for more information. Note that selecting this option disables the ClickFcn edit field.

Annotation Callback Functions

You can associate the following callback functions with annotations.

Click Function

A click function is an M function that the Simulink software invokes when a user single-clicks an annotation. You can associate a click function with any of a model's annotations (see Associating Click Functions with Annotations). the Simulink software uses the color blue to display the text of annotations associated with click functions. This allows the user to see at a glance which annotations are associated with click functions. Click functions allow you to add hyperlinks and custom command "buttons" to your model's block diagram. For example, you can use click functions to allow a user to display the values of workspace variables referenced by the model or to open related models simply by clicking on annotations displayed on the block diagram. (See Referencing a Model.)

Load Function

This function is invoked when it loads the model containing the associated annotation. To associate a load function with an annotation, set the LoadFcn property of the annotation to the desired function (see Annotations API).

Delete function

This function is invoked before deleting the associated annotation. To associate a delete function with an annotation, set the DeleteFcn property of the annotation to the desired function (see Annotations API).

Associating Click Functions with Annotations

Two ways are provided to associate a click function with an annotation via the annotation's properties dialog box (see Annotations Properties Dialog Box). You can specify either the annotation itself as the click function or a separately defined function. To specify the annotation itself as the click function, enter a valid MATLAB expression in the dialog box's Text field and check the Use display text as callback option. To specify a separately defined click function, enter the M-code that defines the click function in the dialog box's ClickFcn edit field.

The following model illustrates the two ways to associate click functions with an annotation.

Clicking either of the annotations in this model displays help for the set_param command.

Selecting and Editing Annotations Associated with Click Functions

Associating an annotation with a click function prevents you from selecting the annotation by clicking on it. You must use drag select the annotation. Similarly, you cannot make the annotation editable on the diagram by clicking its text. To make the annotation editable on the diagram, first drag-select it, then select Edit Annotation Text from model editor's Edit or the context menu.

Annotations API

An application program interface (API) is provided that enables you to use M programs to get and set the properties of annotations. The API comprises the following elements:

Using TeX Formatting Commands in Annotations

You can use TeX formatting commands to include mathematical and other symbols and Greek letters in block diagram annotations.

To use TeX commands in an annotation:

  1. Select the annotation.

  2. Select Enable TeX Commands from model editor's Format menu.

  3. Enter or edit the text of the annotation, using TeX commands where needed to achieve the desired appearance.

    See Mathematical Symbols, Greek Letters, and TeX Characters in the MATLAB documentation for information on the TeX formatting commands which are supported.

  4. Deselect the annotation by clicking outside it or typing Esc.

    The formatted text is displayed.

Creating Annotations Programmatically

You can use the add_block command to create annotations at the command line or in an M-file program. Use the following syntax to create the annotation:

add_block('built-in/Note','path/text','Position', ...
[center_x, 0, 0, center_y]); 

where path is the path of the diagram to be annotated, text is the text of the annotation, and [center_x, 0, 0, center_y] is the position of the center of the annotation in pixels relative to the upper left corner of the diagram. For example, the following sequence of commands

new_system('test')
open_system('test')
add_block('built-in/Gain', 'test/Gain', 'Position', ...
[260, 125, 290, 155])
add_block('built-in/Note','test/programmatically created', ...
'Position', [550 0 0 180])

creates the following model:

To delete an annotation, use the find_system command to get the annotation's handle. Then use the delete function to delete the annotation, e.g.,

delete(find_system(gcs, 'FindAll', 'on', 'type', 'annotation'));
  


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