isgraphics

Tests whether a value is a valid graphics object handle.

Category: Language Fundamentals > Data Types

Syntax

tf = isgraphics(H)

Returns true for each element of H that is a valid graphics handle.

tf = isgraphics(H, type)

Also requires the object to be of the given type, such as 'line' or 'axes'.

Description

A handle becomes invalid when its object is deleted, so isgraphics is the way to check that a stored handle still points at something alive. Ordinary numbers are never graphics handles, unlike the older ishandle, which also accepted numeric handles of existing figures.

Input arguments

H
Value or array of values to test.
type
Type name such as 'figure', 'axes' or 'line'.

Output arguments

tf
Logical array the same size as H.

Example

Checking a line handle

h = plot(1:3);
isgraphics(h)
isgraphics(h, 'line')
isgraphics(h, 'axes')
isgraphics(5)
Output
ans = logical
   1
ans = logical
   1
ans = logical
   0
ans = logical
   0

See also

ishandle isvalid gca gcf plot