title: Creating annotation boxes for subplots in a for-loop in Matlab
body: <p>I have the following code in Matlab that runs through a for loop, reads data from a file and plots 9 different figures, that correspond to some particular "channels" in my data, so I decided to annotate them in the for loop. </p>
  
  <pre><code> clear
   clc
  
   for i=1:9
   subplot(3,3,i);
  hold on
  x = [4 13];  % from your example
  y = ([1 1]);    % from your example
  y2 = ([-0.4 -0.4]);
  H=area(x,y,'LineStyle','none',...
  'FaceColor',[1 0.949019610881805 0.866666674613953]);
  H1=area(x,y2,'LineStyle','none',...
  'FaceColor',[1 0.949019610881805 0.866666674613953]);
  % Create textbox
  annotation('textbox',...
  [0.719849840255583 0.603626943005185 0.176316293929713 0.308290155440411],...
  'String',{'FABLIGHT04','Channel',i},...
  'FontWeight','bold',...
  'FontSize',10,...
  'FontName','Geneva',...
  'FitBoxToText','off',...
  'EdgeColor','none');
  axis([0 24 -0.4 1])
  set(gca,'XTick',[0:1:24])
  set(gca,'YTick',[-0.4:0.2:1])
  xlabel('Time (s)');
  
  
  
   end
  </code></pre>
  
  <p>Initially it was giving me 9 different figures and the annotation thing worked fine. But I wanted to be able to tile them onto a subplot for easier comparison. </p>
  
  <p>Since I switched over to using subplot, it does not annotate my figure properly. On opening the editing dock and generating the code, I find that matlab is plotting everything first and then just putting the annotation boxes in the same figure, one on top of the other. Looking at the code it generated, it apparently takes this part of the code:</p>
  
  <pre><code> annotation('textbox',...
  [0.719849840255583 0.603626943005185 0.176316293929713 0.308290155440411],...
  'String',{'FABLIGHT04','Channel',i},...
  'FontWeight','bold',...
  'FontSize',10,...
  'FontName','Geneva',...
  'FitBoxToText','off',...
  'EdgeColor','none');
  </code></pre>
  
  <p>and does it as:</p>
  
  <pre><code>annotation(figure1,'textbox'...)
  etc etc
  </code></pre>
  
  <p>So for all 9 text boxes, it puts them onto the same figure. I tried to do <code>S=subplot(3,3,i)</code> then <code>annotation(S,'textbox') etc etc</code>, I have also tried <code>S(i)=subplot(3,3,i)</code> and then <code>annotation(S,'textbox') etc etc</code> but nothing seems to work. </p>
  
  <p>I have also tried to change the location of the box. I can't seem to figure out how to make it smaller either.</p>
  
  <p>Does anyone know how to have annotation boxes in the right subplot in a for loop?</p>
  
  <p>Thanks</p>