Why does textbox have 3 reserved words?
5 次查看(过去 30 天)
显示 更早的评论
This is more idle curiosity than a problem to solve, whilst reading the documentation on textbox annotation I saw the note on 3 reserved words.
Being the inquisitive idiot I am I tried the following.
annotation(gcf,'textbox','String','factory')
resulting in blank textbox as the word factory is deleted, as described by the documentation. Just curious I then tried
annotation(gcf,'textbox','String','factory of the future')
Which works and displays the full text, so the string has to be the single word, no more no less. The three words being remove, default & factory.
I noticed you could escape the word hence '\factory' so that it will print so I thought it might have something to do with the Interpreter so I set that to 'none'. That didn't make any difference.
So I'm left puzzling why those three words? What is their signicance and why do they need to be removed?
My final idle thought with three words was to see if it was some subtle easter egg or GCHQ entrance puzzle but 'What three words' gives various locations, depending on the order, in Utah, Dakota, Minnisota or Michigan.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1392969/image.png)
0 个评论
采纳的回答
Adam Danz
2023-5-24
编辑:Adam Danz
2023-5-25
Those are the exact locations of our MATLAB Online servers! 😀 j/k
You may have also noticed the same information in our text properties page. I remember stumbling upon this years ago in grad school when "default" would not appear as a text label and it took me a while to figure out why. This topic has come up before in the forum (2009, 2017) but I couldn't find an explanation so I'll give it a shot.
These key words, default, factory, and remove, come from our top secret default system. Actually, it's not a secret, it's documented, but I don't often see it being used by users. If any readers are exceptions, I'd love to hear from you in the comments below.
Most graphics properties participate in the defaults system which can be set in two ways: through default values defined in the object's ancestor and or through default or factory values set from the graphics root (groot). Factory values cannot be changed by the user but users can set their own default values for these graphics properties.
Factory example
The factory value for text and annotation box strings is empty.
get(groot, 'FactoryTextString') % text
get(groot, 'FactoryTextboxshapeString') % annotation textbox
When you define the string of a text object as "factory" it pulls the factory value from the graphics root.
fig = figure('visible','off'); % we don't need to see the figure
h = annotation(gcf,'textbox','String','factory');
h.String
Default example
For annotation text boxes, the default string value can be set from the graphics root or from the figure and these two default values do not need to agree. If the default value is defined for the ancestor object, it is preferred by objects sharing that ancestor over the graphics root default value.
set(groot,'defaultTextboxshapeString','grootDefaultString') % Graphics root default
h = annotation(gcf,'textbox','String','default');
h.String
set(fig, 'defaultTextboxshapeString', 'figureDefaultString'); % figure default
h = annotation(gcf,'textbox','String','default');
h.String
Remove example
When setting default values, the remove keyword removes the default value so that the factory value prevails. Continuing from the lines above,
get(groot, 'defaultTextboxshapeString')
If we clear it, the default string value returns to the factory value
set(groot, 'defaultTextboxshapeString', 'remove')
get(groot, 'defaultTextboxshapeString')
When restore is applied to the annotation box string, it behaves like default.
set(fig, 'defaultTextboxshapeString', 'figureDefaultString');
h = annotation(gcf,'textbox','String','remove');
h.String
Why?
For why-questions, ask MATLAB
why()
更多回答(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!