필터 지우기
필터 지우기

What is the difference between ishghandle and isgraphics?

조회 수: 3 (최근 30일)
Adam
Adam 2016년 12월 7일
댓글: Adam 2016년 12월 8일
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