This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Graphics Object Handles

What You Can Do with Handles

A handle refers to a specific instance of a graphics object. Use the object handle to set and query the values of the object properties.

When you create graphics objects, you can save the handle to the object in a variable. For example:

x = 1:10;
y = x.^2;
plot(x,y);
h = text(5,25,'*(5,25)');

The variable h refers to this particular text object '*(5,25)', which is located at the point 5,25. Use the handle h to query and set the properties of this text object.

Set font size

h.FontSize = 12;

Get font size

h.FontSize
ans =

     12

Make a copy of the variable h. The copy refers to the same object. For example, the following statements create a copy of the handle, but not the object:

hNew = h;
hNew.FontAngle = 'italic';
h.FontAngle
ans =

italic

What You Cannot Do with Handles

Handles variables are objects. Do not attempt to perform operations involving handles that convert the handles to a numeric, character, or any other type. For example, you cannot:

  • Perform arithmetic operations on handles.

  • Use handles directly in logical statements without converting to a logical value.

  • Rely on the numeric values of figure handles (integers) in logical statements.

  • Combine handles with data in numeric arrays.

  • Convert handles to character vectors or use handles in character vector operations.

Related Topics