title: How to put text inside Rectangle in MATLAB?
body: <p>I am using <a href="https://in.mathworks.com/help/matlab/ref/rectangle.html?searchHighlight=rectangle&amp;s_tid=doc_srchtitle" rel="nofollow noreferrer">Rectangle</a> to create a fishnet in MATLAB. Each box of the fishnet shows some value that I am reading from a matrix.</p>
  
  <p><a href="https://i.stack.imgur.com/iy4Ob.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iy4Ob.jpg" alt="enter image description here"></a></p>
  
  <p>In the attached figure white boxes represent <code>NaN</code>, whereas yellow boxes have numbers like 1,2,3,4,5,6,7,8,9.. Here, I want to write these numbers inside the yellow boxes. </p>
  
  <p>How to do this? Below is my script,</p>
  
  <pre><code>for row=1:size(Data,1)
      for col=1:size(Data,2);
  
          if isnan(Data(row,col))
              rectangle('Position',[col-0.5 row 1 1], 'FaceColor','w','EdgeColor','k', 'LineWidth', 0.1)
          else
              rectangle('Position',[col-0.5 row 1 1], 'FaceColor','y','EdgeColor','k', 'LineWidth', 0.1)
              axis equal            
              str = num2str(Data(row,col));
              annotation('String',str);         
          end
  
          set(gca,'Visible','off')  
  end
  </code></pre>