Why does ishghandle(0) alwys return true?

조회 수: 1 (최근 30일)
Georg Nestlinger
Georg Nestlinger 2021년 1월 26일
댓글: Georg Nestlinger 2021년 1월 28일
Why does
ishghandle(0)
return true, even if there is no existent graphic object (actually, I executed this line of code first after Matlab startup).

채택된 답변

Stephen23
Stephen23 2021년 1월 26일
편집: Stephen23 2021년 1월 26일
Because the graphics root always exists:
Using zero is discouraged now, but in versions prior to R2014b was equivalent to groot:

추가 답변 (1개)

Georg Nestlinger
Georg Nestlinger 2021년 1월 26일
I'd like to extend my question. The source of the problem was the following:
I initilized a graphics object using
gobjects(1)
Then, checking with ishghandle() worked as expected in R2014b and above, but failed in R2013a.
What would be the recommended way for pre R2014b (I guess that was the release the new graphis system was introduced), ideally giving same results in R2013a and R2014b?
  댓글 수: 4
Stephen23
Stephen23 2021년 1월 26일
AFAIK, versions before R2014b used numeric (double) scalars as a kind of graphics object "handle" (really more like an ID number). My guess is that the functions that "check" the existence simply have a different behavior when applied to doubles (IDs) vs graphics object handles.
In the back of my head I recalled an earlier discussion on this topic, but I can't find it now.
Is it really required to test for the existence of the graphics object? Surely if you are the author of your GUI and you keep track of the objects (by storing them in arrays, etc.), then there is little need to "guess" what graphics objects might be hanging around.
Georg Nestlinger
Georg Nestlinger 2021년 1월 28일
I'm using this for a visualization in Simulink and i want the figure to be created when the simulation starts or if I closed it unintentionally.
It seems that using the undocumented second argument like
ishghandle(obj, 'figure')
does what I want. So I will go with this approach for now.

댓글을 달려면 로그인하십시오.

카테고리

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