Save an annotation onto a figure programmatically in app designer
Afficher commentaires plus anciens
I have a modelling app which I use to show effects of noise on solitons.

The graph loads/saves/edits fine. The "Create Info Panel" also works...

BUT...
I cannot save the annotation panel on the figure. If I load a figure into MATLAB directly and use the property inspector to create an annotation then I can save it as *.fig and it saves the annotation which then loads.

I have examined everything from groot; figure; axes... to look for where the annotation is linked to the figure but simply cannot find it. In my code the axis and children are copied to the panel and the annotation is attached to the panel through
app.tbx = annotation(app.GraphViewPanel,'textbox',...
[app.XSpinner.Value app.YSpinner.Value app.WSpinner.Value app.HSpinner.Value], ...
'Interpreter','latex');
set(app.tbx,'string',str);
set(app.tbx,'FontSize',app.HSpinner_2.Value);
The graph is created by
app.Figure2Edit = openfig(app.NameTemp, 'invisible');
...
ax_to_copy = app.Figure2Edit.Children;
app.ax = copyobj(ax_to_copy,app.GraphViewPanel);
If you remove invisible then the created in MATLAB annotation shows up on the MATLAB figure but not on my panel. Clearly the annotation is not a child object of the figure so where is it stored/associated/kept. The irony is that I can find a reference to a text object in the MATLAB version immediately above but only if it is active as shown.
close all; format compact;
file = 'U_L250run5P_Avg.fig';
f_new = openfig(file);
ax = findobj(f_new)
gives the figure above and
ax =
8×1 graphics array:
Figure (1)
UIAxes
Line
Line
Line
Line
Line
Line
ax(1) gives the figure and its properties and nothing helpful, Children: [1×1 UIAxes] shows no sign of the two lines of text in the annotation. Clicking on the "edit Plot" arrow and rerunning ax(1) now shows
CurrentObject: [1×1 TextBox]
whereas befor highlighting it showed
CurrentObject: [0×0 GraphicsPlaceholder]
Until I know where in the hierarchy of objects the annotation belongs and how it fits in to the figures that MATLAB saves, I am stuck with editting and saving these figures. They do not copy though I can use snipping tool but that means I have to recreate the same figure each time as I cannot save and load it. A map would be wonderful!!
1 commentaire
Fangjun Jiang
le 7 Mar 2024
annotation(container,___) creates the annotation in the figure, uipanel, or uitab specified by container, instead of in the current figure.
text(ax,___) creates the text in the Cartesian, polar, or geographic axes specified by ax instead of in the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!