Create an Annotation Programmatically

Annotations API

Use MATLAB® code to get and set the properties of annotations.

  • Simulink.Annotation class

    Set the properties of annotations.

  • getCallbackAnnotation function

    Get the Simulink.Annotation object for the annotation associated with the currently executing annotation callback function. Use this function to determine which annotation invoked the current callback. This function is also useful if you write a callback function in a separate MATLAB file that contains multiple callback calls.

Create Annotations Programmatically

To create annotations at the command line or in a MATLAB program, use the add_block command. For example:

open_system('vdp');
block = add_block('built-in/Note', ...
'vdp/This simulates a nonlinear second order system', ...
'Position', [200 250])

Alternatively, you can use a Simulink.Annotation object to create an annotation. For example:

open_system('vdp')
note = Simulink.Annotation('vdp/This is an annotation');
note.position = [10,50]

Delete an Annotation Programmatically

To delete an annotation programmatically, use the find_system command to get the annotation handle. Then use the delete function to delete the annotation. For example:

delete(find_system(gcs, 'FindAll', 'on', 'type', 'annotation',...
'text', 'programmatically created'));

Find Annotations in a Model

Use command such as this to find all of the annotations in a model.

open_system('vdp')
annotations = find_system(gcs,'FindAll','on','Type','annotation')
annotations =

   34.0004
   33.0009

See the find_system documentation for specifying levels of the model to search.

To identify the annotation handle of annotations, enter:

get_params(annotations,'Name')
ans = 

    'Copyright 2004-2014 The MathWorks, Inc.'
    'van der Pol Equation'

Show or Hide Annotations Programmatically

When you create an annotation, by default it appears in the model. You can configure an annotation to be a markup annotation, which you can hide.

To find out whether the first annotation is a markup annotation, use commands such as this:

open_system('vdp')
annotations = find_system(gcs,'FindAll','on','Type','annotation')
get_param(annotations(1),'MarkupType','markup')

To configure the first annotation in a model so that it can be hidden, use a commands such as this:

set_param(annotations(1),'MarkupType','markup')

To reconfigure that annotation to always appear, use this command:

set_param(annotations(1),'MarkupType','model')

To find out whether a model is configured to show or hide markup annotations, use a command such as this command for the vdp model:

get_param(vdp,'ShowMarkup')

To configure a model to hide markup annotations, use a command such as this:

get_param(vdp,'ShowMarkup','off')

Related Examples

More About

Was this topic helpful?