| Simulink® | ![]() |
| On this page… |
|---|
Annotations Properties Dialog Box Associating Click Functions with Annotations |
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 replace the annotation, click the annotation, then double-click or drag the cursor to select it. Then, enter the new annotation.
To insert characters, click between two characters to position the insertion point, then insert text.
To replace characters, drag the mouse to select a range of text to replace, then enter the new text.
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.
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.
Displays the current text of the annotation. Edit this field to change the annotation text.
Checking this option causes a drop shadow to be displayed around the annotation, giving it a 3-D appearance.
Checking this option enables use of TeX formatting commands in this annotation. See Using TeX Formatting Commands in Annotations for more information.
Clicking this button displays a font chooser dialog box. Use the font chooser to change the font used to render the annotation's text.
Specifies the color of the annotation text.
Specifies the color of the background of the annotation's bounding box.
Specifies the alignment of the annotation's text relative to its bounding box.
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.
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.
You can associate the following callback functions with annotations.
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.)
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).
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).
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.
Note You can also use M-code to associate a click function with an annotation. See Annotations API for more information. |
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.
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:
Simulink.Annotation class
Allows M-code, e.g., annotation load functions (see Load Function), to set the properties of annotations
getCallbackAnnotation function
Gets the Simulink.Annotation object for the annotation associated with the currently executing annotation callback function
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:
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.
Deselect the annotation by clicking outside it or typing Esc.
The formatted text is displayed.

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'));
![]() | Aligning, Distributing, and Resizing Groups of Blocks | Creating Subsystems | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |