Graphics Previous page   Next Page

Copying Objects

You can copy objects from one parent to another using the copyobj function. The new object differs from the original object only in the value of its Parent property and its handle; it is otherwise a clone of the original. You can copy a number of objects to a new parent, or one object to a number of new parents, as long as the result maintains the correct parent/child relationship.

When you copy an object having child objects, MATLAB copies all children as well.

Example -- Copying Objects

Suppose you are plotting a variety of data and want to label the point having the x- and y-coordinates determined by in each plot. The text function allows you to specify the location of the label in the coordinates defined by the x- and y-axis limits, simplifying the process of locating the text.

In this statement, the text function

To label the same point with the same string in another plot, copy the text using copyobj. Because the last statement did not save the handle to the text object, you can find it using findobj and the 'String' property.

After creating the next plot, add the label by copying it from the first plot.

This particular example takes advantage of the fact that text objects define their location in the axes data space. Therefore the text Position property did not need to change from one plot to another.


Previous page  Searching for Objects by Property Values -- findobj Deleting Objects Next page

© 1994-2005 The MathWorks, Inc.