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

You can use a Simulink.Annotation object to create an annotation. For example:

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

To create an area, use the add_block function. You can position the area in the model using the Position parameter.

add_block('built-in/Area','vdp/This is an Area','Position',[120,100,230,200])

Delete an Annotation Programmatically

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

'text','programmatically created'));

Find Annotations in a Model

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

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


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

To identify the annotation handle of annotations, enter:

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:

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

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


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


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


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


See Also

Related Topics