- Zero is a numeric scalar. This means that it is a number.
- groot is an object, the root of all graphics objects. This means it has methods and properties..
Are these the same: set(0, ... and set(groot, ...
20 次查看(过去 30 天)
显示 更早的评论
Let's say I always want graphics to appear a certain way, so I put commands to set graphic preferences in my startup.m file. I have seen some suggestions where these commands are implemented as
set(0, ....
and some where they are implemented as
set(groot, ....
Based on the documentation for groot and this answer, I think they are interchangable, and the graphic preference will be implemented for any figure I make in the current matlab session, but not in future Matlab sessions unless I re-run them in startup. Is this right? I also think "set(0,..." is just an older implementation of groot, which is why I can't find in in the documentation.
0 个评论
采纳的回答
Stephen23
2020-2-20
编辑:Stephen23
2020-2-20
"Are these the same: set(0, ... and set(groot, ..."
No, they are not the same. Not even close to being the same.
The reason why that outdated Answers thread mentions zero is because it was written just as some huge changes were being made to the graphics engine, which was released with version R2014b:
As you can see, everything changed, not just how the graphics root is referred to.
But, as a matter of convenience and to allow for some backward compatibilty, some of the old ways of referring to old style graphics objects still work, e.g. using number handles. But the documentation, blogs, and answers on this topic make it quite clear that using these outdated syntaxes is discouraged, e.g. "This capability is provided to help make it easier to update code to work with the new graphics system, but should not be used as a permanent fix."
If you want the official TMW explanation of the difference between 0 and groot, read part 2 of this series:
"I have seen some suggestions ..."
Which is a good example of why following random "suggestions" is never as good as reading the documenation.
2 个评论
Guillaume
2020-2-20
I think that not even close to being the same is a bit strong in the context of the question. set(0,...) and set(groot,...) do achieve exactly the same result, changing the properties of the grahics root. I'm not aware of set(0, ...) stopping to work anytime soon.
However, yes in modern code, you should use groot since numeric graphics handles have long been deprecated and 0 has only been kept for backward compatibilty. On the other hand, some people still prefer to use other backward compatible constructs such as cellfun('size',...) ;)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!