Copy graphics objects and their descendants
new_handle = copyobj(h,p)
copyobj(___,'legacy')
copyobj
creates copies of graphics objects
and assigns the objects to the new parent.
The new parent must be appropriate for the copied object (for
example, you can copy an axes only to figure or uipanel). copyobj
copies
children as well.
new_handle = copyobj(h,p)
copies
one or more graphics objects identified by h
and
returns the handle of the new object or an array of new objects. The
new graphics objects are children of the graphics objects specified
by p
.
copyobj(___,'legacy')
copies
object callback properties and object application data. This behavior
is consistent with versions of copyobj
before MATLAB® release
R2014b.
copyobj
does not copy properties or objects
that depend on their original context to operate properly. Objects
with default context menus (such as legends and colorbars) create
new context menus for the new object. Figures create new toolbars
and menus for the new figure.
copyobj
does not copy:
Callback properties (except when using the legacy
option)
Application data associated with the object (except
when using the legacy
option)
Context menu of legends, colorbars, or other objects that define default context menus.
Default Figure toolbar and menus
You cannot copy the same object more than once to
the same parent in a single call to copyobj
.
MATLAB changes the Parent
property to
the new parent and assigns the new objects a new handle.
Copy a surface to a new axes that is in a different figure.
h = surf(peaks); colormap hsv
Create the destination figure and axes:
fig = figure; ax = axes;
Copy the surface to the new axes and set properties that are not surface properties:
new_handle = copyobj(h,ax);
colormap(fig,hsv)
view(ax,3)
grid(ax,'on')
Note that while the surface is copied, the colormap
, view
,
and grid
are not copied.