Create an object group by parenting objects to a group or transform
object. For example, call
create a group object and save its handle. Assign this group object
as the parent of subsequently created objects:
hg = hggroup; plot(rand(5),'Parent',hg) text(3,0.5,'Random lines','Parent',hg)
Setting the visibility of the group to off makes the line and text objects it contains invisible.
hg.Visible = 'off';
You can add objects to a group selectively. For example, the
following call to the
bar function returns the
handles to five separate bar objects:
hb = bar(randn(5))
hb = 1x5 Bar array: Bar Bar Bar Bar Bar
Parent the third, fourth, and fifth bar object to the group:
hg = hggroup; set(hb(3:5),'Parent',hg)
Plotting functions clear the axes before generating their graph.
However, if you assign a group or transform as the
the plotting function, the group or transform object is not cleared.
hg = hggroup; hb = bar(randn(5)); set(hb,'Parent',hg)
Error using matlab.graphics.chart.primitive.Bar/set Cannot set property to a deleted object
bar function cleared the axes. However,
if you set the
Parent property as a name/value
pair in the
bar function arguments, the bar function
does not delete the group:
hg = hggroup; hb = bar(randn(5),'Parent',hg);
Visible property of a group or
transform object controls whether all the objects in the group are
visible or not visible. However, changing the state of the
for the group object does not change the state of this property for
the individual objects. The values of the
for the individual objects are preserved.
For example, if the
Visible property of the
group is set to off and subsequently set to on, only the objects that
were originally visible are displayed.
The same behavior applies to the
The children of the group or transform object show the state of the
containing object properties without actually changing their own property