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:
annotation('textbox',[0,0,1,1],'String','+',...
'FontName','Arial','FontSize',108,...
'Color',cross_color,...
'EdgeColor','none',...
'HorizontalAlignment','center','VerticalAlignment','middle');
annotation('rectangle',[0,0.45,0.05625,0.1],'Color','k','FaceColor','k');
drawnow;

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');
set([h1,h2],'visible','on')
  3 Comments
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
drawnow()
%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 http://psychtoolbox.org/
  2 Comments
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!