MATLAB: How to put a hat on a character displayed in a text object within a figure in MATLAB

hatlatexMATLABtext;titlexlabelylabelzlabel

I would like to put a hat (^) on a character that is displayed in an X-Label, Y-Label, Z-Label, Title or other text object within a figure in MATLAB.

Best Answer

As of MATLAB 7.0 (R14), "LaTeX" has been added as an optional interpreter for text objects in a figure.
In order to put a hat on a character that is to be displayed within a figure, the "Interpreter" property of the text should to be set to "LaTeX" and the equivalent LaTeX command "\hat{x}" should be typed as "$$\hat{x}$$".
For example, to have "x-hat" displayed in the X-Label, do the following:
xlabel('$$\hat{x}$$','Interpreter','Latex')
Another example to have "x-hat" displayed as text is:
text(xp,yp,'$$\hat{x}$$','Interpreter','Latex')
where "xp" and "yp" determine the position of the displayed text.
There are no known workarounds for MATLAB 6.5.1 (R13SP1) or earlier versions.