What is the difference between ishghandle and isgraphics?

7 次查看(过去 30 天)
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 个评论
dpb
dpb 2016-12-7
编辑:dpb 2016-12-7
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.

请先登录,再进行评论。

采纳的回答

David Barry
David Barry 2016-12-7
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 个评论
Adam
Adam 2016-12-8
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by