MATLAB Answers

How to achieve identical timing of two side by side annotations

16 views (last 30 days)
Kara Presbrey
Kara Presbrey on 9 Apr 2021 at 20:06
Commented: Walter Roberson on 9 Apr 2021 at 21:49
I have a figure that is just a full-screen white box. On this figure, I want to draw a green cross in the center, and a colored rectangle at the same height but at the left edge of the screen. It's very important that these two annotations appear at the exact same time for a research project.
This is what I am currently doing, but I don't really know for sure how it works and am worried that the cross annotation might be drawn before the rectangle is drawn:

Answers (2)

Fangjun Jiang
Fangjun Jiang on 9 Apr 2021 at 20:18
What you can do is this. I think it can improve the timing.
h1=annotation(..., 'visible','off'):
h2=annotation(..., 'visible','off');
Walter Roberson
Walter Roberson on 9 Apr 2021 at 21:48
Tricky. Annotations are not made to the current axes. Annotations are drawn into a pane that is logically "in front" of all other items, using figure coordinates (not data coordinates!). The first annotation() for the figure could potentially involve creation of an annotation pane.
Hmmm... looks like perhaps these days annotations are potentially in uipanel() or uitab() rather than in figures directly, so there could be multiple such objects per figure, so it would make even more sense for the first annotation() call in the container to need to build the annotation pane.
Which suggests that potentially if you did
h0 = annotation(something, 'visible', 'off'); %force annotation pane to be built
%now draw the two useful annotations. In theory should not need 'visible',
%'off' for this.
then you just might get more consistent timing.

Sign in to comment.

Walter Roberson
Walter Roberson on 9 Apr 2021 at 20:20
For anything like this you should probably be using the third party Psychtoolbox
Walter Roberson
Walter Roberson on 9 Apr 2021 at 21:49
Could you use Computer Vision Toolbox insertText() and insertShape() to draw into an array, then image() the array so that everything becomes visible at the same time?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!