Main Content

Test for Valid Handle

Use isgraphics to determine if a variable is a valid graphics object handle. A handle variable (h in this case) can still exist, but not be a valid handle if the object to which it refers has been deleted.

h = plot(1:10);
...
close % Close the figure containing the plot
whos
Name      Size            Bytes  Class                       Attributes

  h       1x1             104    matlab.graphics.chart.primitive.Line 

Test the validity of h:

isgraphics(h)
ans =

     0

For more information on deleted handles, see Deleted Handle Objects.