These three commands:
text(x,y,mystr)
annotation('textbox','String',mystr)
uicontrol('Style','text','String',mystr)
create three different types of text objects which are used for different jobs.
- The first one creates a graphics text object which goes in an axes. It will pay attention to things like xlim and ylim, and it does support the latex interpreter.
- The second one creates a different type of graphics text object which draws over all of the axes. It also supports the latex interpreter, but it's not going to pay attention to things like xlim and ylim.
- The third one creates a uicontrol with a text string in it. It does not support the latex interpreter, so you can't use it for this job.
In your code snippet:
- You have a variable named hObject. I'm not sure what that's supposed to be. I don't think you want that.
- In the call to annotation, you're passing in an X & Y argument. The annotation command doesn't want those. That's the syntax for the text command.
The annotation command creates an object with a Position property. That's a rectangle with four values [x y w h]. Those are in normalized units (i.e. 0 to 1), where the X & Y for the text command are in the coordinate system of the axes. I can use it like this:
h = annotation('textbox','String',D);
h.Position=[.5 .5 .2581 .0929];
If the width of your box is too small to hold the string, then it will try to wrap it into multiple lines. Unfortunately, that doesn't work well with LaTeX because it doesn't know enough about where it can safely break the equation. The best way to deal with that is to use the property named 'FitBoxToText':
That will recompute the width so that your equation will fit on one line.
Best Answer