MATLAB: How to place an overbar over text using “LATEX” as the “Interpreter” in MATLAB 7.0 (R14) and later versions

evaluateinterpreterlatexMATLABoverbaroverlinetext;

I would like to place an overbar over text using "LATEX" as the "Interpreter" and I would also like to display the values of variables or the results of evaluated expressions as part of the string in a TEXT object.

Best Answer

The following example illustrates how to:
(1) Put an overbar over the text string, "5*pi/4", using "\overline" option.
(2) Evaluate an expression within the TEXT command. In this case, the value of "sin(5*pi/4)" will be evaluated and displayed.
figure
plot(0:pi/20:2*pi,sin(0:pi/20:2*pi))
text('interpreter','latex','string',['$sin(\overline {5*pi/4} ) = ',num2str(sin(5*pi/4)),'$'],...
'FontSize',16)
Similarly, to display this line in the title, (or xlabel or ylabel), use,
title(['$sin(\overline {5*pi/4} ) = ',num2str(sin(5*pi/4)),'$'],'interpreter','latex','FontSize',16)
where the command TITLE can be swapped out with XLABEL or YLABEL directly.
Related Question