Are annotations supported in uifigure objects?

Answers (1)

I asked an internet search engine for "Matlab annotations appdesigner" and the first hit is https://www.mathworks.com/help/matlab/creating_guis/graphics-support-in-app-designer.html. Here you find:
However, the following functionality is not supported:
...
Annotations and Colormap Adjustments: annotation
This sounds like annotations are not supported.
Although I really like this forum, I admit that Google took only 0.47 sec to find the link, while I typed for minutes to post, what was found automatically. Therefore it is recommended to search before asking.

8 Comments

Thanks, Jan. I'm getting all those errors too, which is what prompted my question. I guess what I really should have asked is if there's another similar feature that >does< work in uifigures. Or does Mathworks plan to add this functionality?
I suspect Mathworks does plan to add this, but I have no idea what their timeframe is.
Meanwhile the work-around is text() and line()
or uilabel if you'd like text off the plot.
According to the updated documentation, annotation objects are supported in appdesigner (same link provided by Jan).
uif = uifigure();
x = [0.3 0.5];
y = [0.6 0.5];
annotation(uif,'arrow',x,y)
However, unlike regular figures, the annotation object does not appear on top of existing axes in UIFigures, at least not in r2020a.
Here's a demo that creates two figures, one is a UIFigure. Each figure has identical axes and identical annotiation boxes. The annotation object is not seen in the UIFigure. A confirmation box will appear in the UIFigure and when you press a button, it will delete the UIAxes and the annotation object will be revealed.
fig = figure('Units','pixels');
fig.Position = [150,150,560,420];
ax = axes(fig, 'Units','Pixels', 'Position', [25 25 510 380]);
an = annotation(fig, 'TextBox',[.2 .2 .6 .6],'String','Anotation Text Box');
uifig = uifigure('Position',[sum(fig.Position([1,3]))+10,fig.Position(2:end)]);
uiax = uiaxes(uifig,'Position',ax.Position);
uian = annotation(uifig, 'TextBox',[.2 .2 .6 .6],'String','Anotation Text Box');
waitfor(uiconfirm(uifig,'Press any button to remove UIAxes and reveal the annotation object.', 'Annotation demo'));
delete(uiax)
Are there any solutions (or hacks) to this?
Andrew please clarify what it is you are trying to solve.
I'll make a guess as to what Andrew is interested in (at least it is what I'm interested in).
hf = uifigure ();
ha = axes ('parent', hf);
h = annotation ('line', [0.1, 0.9], [0.1, 0.9]);
h.Parent = ha;
plotedit (ha, 'on')
If uifigure is replaced by figure, then I can use the mouse to move the line, or its ends. This is essentially the same as imline, but does not require the image processing toolbox.
When uifigure is used, the parent cannot be specified by the annotation line. As a result a figure is created. When the annotation parent is changed to the UIAxes, the ability to modify the line via the mouse no longer works.
I'm running 2022b. The following works, but ...
hf = uifigure ('Name', 'annotate');
ha = uiaxes ('parent', hf, 'units', 'normalized', 'position', [0, 0, 1 1], 'looseinset', 0.03 * [1 1 1 1]);
htmp = figure ();
h = annotation ('line', [0.1, 0.9], [0.1, 0.9]);
h.Parent = ha;
close (htmp)
... I'd also like to be able to allow the line to be changed via the mouse. The following allows that, but also allows the everything else to be modified by the mouse.
plotedit (hf, 'on')
ha.Selected = 'off';
h.Selected = 'on';

Sign in to comment.

Asked:

on 4 Jan 2018

Commented:

on 22 Jun 2024

Community Treasure Hunt

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

Start Hunting!