Why does textbox have 3 reserved words?

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Adam Danz
Adam Danz il 24 Mag 2023
Modificato: Adam Danz il 25 Mag 2023
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
ans = 0×0 empty char array
get(groot, 'FactoryTextboxshapeString') % annotation textbox
ans = 1×1 cell array
{0×0 char}
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
ans = 1×1 cell array
{0×0 char}
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
ans = 'grootDefaultString'
set(fig, 'defaultTextboxshapeString', 'figureDefaultString'); % figure default
h = annotation(gcf,'textbox','String','default');
h.String
ans = 'figureDefaultString'
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')
ans = 'grootDefaultString'
If we clear it, the default string value returns to the factory value
set(groot, 'defaultTextboxshapeString', 'remove')
get(groot, 'defaultTextboxshapeString')
ans = 1×1 cell array
{0×0 char}
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
ans = 'figureDefaultString'
Why?
For why-questions, ask MATLAB
why()
The smart engineer obeyed some tall kid.
  1 Commento
Adrian Cherry
Adrian Cherry il 25 Mag 2023
Thanks for the comprehensive response - it helps me to understand why those three words. Still pondering on the wisdom of combining functional operations and display text in the one String parameter.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by