Remove graphics objects with the
Pass the object handle as an argument to
For example, delete the current axes, and all the objects contained
in the axes, with the statement.
If you want to delete multiple objects, pass an array of handles
delete. For example, if
h3 are handles to graphics objects that you
want to delete, concatenate the handles into a single array.
h = [h1,h2,h3]; delete(h)
Closing a figure deletes all the objects contained in the figure. For example, create a bar graph.
f = figure; y = rand(1,5); bar(y)
The figure now contains axes and bar objects.
ax = f.Children; b = ax.Children;
Close the figure:
MATLAB® deletes each object.
f = handle to deleted Figure
ax = handle to deleted Axes
b = handle to deleted Bar
When you delete a graphics object, MATLAB does not delete the variable that contains the object handle. However, the variable becomes an invalid handle because the object it referred to no longer exists.
You can delete graphics objects explicitly using the
or by closing the figure that contains the graphics objects. For example,
create a bar graph.
f = figure; y = rand(1,5); b = bar(y);
Close the figure containing the bar graph.
The handle variables still exist after closing the figure, but the graphics objects no longer exist.
Name Size Bytes Class f 1x1 104 matlab.ui.Figure b 1x1 104 matlab.graphics.chart.primitive.Bar y 1x5 40 double
isgraphics to determine
the validity of a graphics object handle.
ans = 0
You cannot access properties with the invalid handle variable.
Invalid or deleted object.
To remove the variable, use the