How to get a surface handle

10 visualizaciones (últimos 30 días)
Rafael Kübler
Rafael Kübler el 21 de Jul. de 2016
Editada: Stephen23 el 21 de Jul. de 2016
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 comentario
Stephen23
Stephen23 el 21 de Jul. de 2016
Editada: Stephen23 el 21 de Jul. de 2016
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!

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Jul. de 2016
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 comentario
Guillaume
Guillaume el 21 de Jul. de 2016
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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by