How to get a surface handle
9 次查看(过去 30 天)
显示 更早的评论
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
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
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
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 Center 和 File 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!