How to get a surface handle

조회 수: 10 (최근 30일)
Rafael Kübler
Rafael Kübler 2016년 7월 21일
편집: Stephen23 2016년 7월 21일
Hello together,
in the Matlab Help for surf it Shows the command
h = surf(...) which returns a handle to a chart surface graphics object.
I'm not quite sure, what h is. Whats the difference to the handle I get, calling gcf?
My question is: How can I get the same handle like h just after I plotted the surface.
So i want to plot the surface with
surf(...) (without using h = surf(....))
and then later get the handle created with h.
Is this possible?
Thank you for your help
  댓글 수: 1
Stephen23
Stephen23 2016년 7월 21일
편집: Stephen23 2016년 7월 21일
There are lots of graphics objects, each with handles. Why not read the documentation, which explains exactly how they are arranged:
Note that keeping and using the actual handle is always going to be faster an more robust. This is much better:
h = surf(...)
than anything involving gcf, gca, or findobj. You should think of these as conveniences for you while playing around in the command window, but never use them for serious code. They are far too unpredictable!

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 7월 21일
gcf returns the handle of the active figure. The figure is the entire window, including all menus, all buttons, all graphs, and so on. The handle returned by surf() is the handle just for the one surface.
If you do not record the handle at the time the surface is created, then you can use findobj to look for it:
findobj(gcf, 'type', 'surface')
provided the current figure has not changed.
  댓글 수: 1
Guillaume
Guillaume 2016년 7월 21일
At the end of the day what is the problem with using hsurf = surf(...)? It's easy and more importantly, it's safe. h is guaranteed to hold the handle to the surface you've created.
Sure, you could find it later using findobj(gcf, 'type', 'surface'), except that gcf may not be the figure where the surface was created, or the figure may have more than one surface, or ... Why worry, keep track of it from the start.
Note that gcf (and gca) are just as dangerous. gcf is the current figure. If you click on a different figure while your code is busy plotting, it will continue plotting on that different figure. It's always safer to keep track of the figure you've created (with hfig = figure).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by