Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an axes handle is cleared or not

I want to check if some axes have been cleared or not, based on which some further task is to be performed. I use cla to clear some axes, not delete. For example:

figure

hs1 = subplot(121); plot(rand(100,2), 'x');

hs2 = subplot(122); plot(rand(100,2), 'o');

cla(hs1)

Then, the question is how to determine if hs1 is cleared.

like image 227
jingweimo Avatar asked Dec 13 '18 19:12

jingweimo


1 Answers

The cla function removes all child objects with visible handles by default. You can therefore check if an axes has been cleared by seeing if it has any child objects using the allchild function:

isCleared = isempty(allchild(hs1));

A couple notes to keep in mind:

  • The cla function will not clear objects with hidden handles by default. The option cla(hs1, 'reset') is needed to clear hidden handles.

  • The allchild function will find all child objects regardless of their handle visibility. If you just want to check for child objects with visible handles, you can use isempty(hs1.Children).

like image 131
gnovice Avatar answered Oct 23 '22 20:10

gnovice