Clear Filters
Clear Filters

What is the difference between ishghandle and isgraphics?

3 views (last 30 days)
This is something that I have wondered for a while. I like to do a lot of validating of things in my code, one of which is to check if some graphics object (e.g. a figure) is still valid or whether I need to recreate it.
I always tended to use ishghandle ( note: not ishandle which I know is different) because I didn't know about isgraphics.
But is there some subtle difference I am not understanding? The descriptions differ only by isgraphics saying it returns true for valid graphics handles. But ishghandle returns false on a deleted axes, closed figure etc too so I am not aware of a case in which these too differ in result.
ishghandle documentation does talk about Simulink objects, though in relation to a comparison with ishandle, but I don't have Simulink so I can't test if this is a place where ishghandle and isgraphics differ.
I guess it doesn't matter and I can use either one if they both return true or false when I want them too, I'm just curious.
  1 Comment
dpb
dpb on 7 Dec 2016
Edited: dpb on 7 Dec 2016
I don't have HG2 so don't have either but from the doc it looks to me like ishghandle is an early incarnation of isgraphics -- it lacks the second optional type argument and the doc doesn't provide the "Introduced" revision level. It would not surprise me to find it deprecated one of these days.
The rate of change recently has really introduced "a veritable plethora" of warts with objects and data types coming into and going out of favor so rapidly it's impossible to keep up and make any heads nor tails of where TMW is really going--not sure they know in long term themselves, they're introducing features so fast there's not time to ever assimilate them all into a cogent whole on a release-by-release basis.

Sign in to comment.

Accepted Answer

David Barry
David Barry on 7 Dec 2016
isgraphics was introduced in R2014b along with HG2. You can replace all instances of ishghandle with isgraphics going forward and your old code will still work. The new optional 2nd input to isgraphics allows you to also check for type.
The old way still works:
H = plot(rand(5));
isgraphics(H)
But you can now also optionally check for type:
H = plot(rand(5));
a = [H;gca;gcf];
isgraphics(a,'line')
MathWorks created a page dedicated to HG2. See here and in particular the sub-page here which talks about checking for valid graphics handles.
  1 Comment
Adam
Adam on 8 Dec 2016
Thanks for that. I never really looked too much at the specific help pages for HG2 graphics because I program using OOP anyway so the change to graphics objects being classes was so natural it just made total sense so I didn't delve too deep into the help to find that, I guess I should have done!

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!