I am trying to do write a simple equation of a plane plus the value of the coefficient \bar{a}_1, a_2 and a_3 but I cannot get the \bar to work. Any suggestion? I tried $\bar{a}_{1}$ with or without dollars, everything else looks fine to me, I used latex or tex interpreter but it cannot recognize it. this is the code:
a1=1
a2=2
a3=3
str = {'LLSQ fit:','z=$\bar{a}_{1}$+a_2x+a_3y',sprintf('$\bar{a}_{1}$=%5.2f',a1),sprintf('a_2=%5.2f',a2),sprintf('a_3=%5.2f',a3)};
annH = annotation('textbox',[0.63 0.8 0.08 0.08],'string',str,'interpreter','latex')
set(annH,'FitBoxToText','on','fontsize', 18,'BackgroundColor',[1 1 1])
thanks
To add subscripts to symbolic variables in live scripts, append the corresponding index to the variable using one underscore ( _ ). For example, create two symbolic variables with subscripts using syms . Use these variables in an expression.
set(groot, 'defaultAxesTickLabelInterpreter','tex'); set(groot, 'defaultLegendInterpreter','tex'); set(0, 'defaultTextInterpreter', 'tex'); legend('\varphi', 'k');
In ubuntu (and possibly other distro's) the latex font is called Latin Modern, or lm for short. You can find them all via: # fc-list | grep lmroman /usr/share/texmf/fonts/opentype/public/lm/lmroman10-bold.
Insert LaTeX Equation To insert a LaTeX equation: Go to the Insert tab, click Equation , and select LaTeX Equation. Enter a LaTeX expression in the dialog box that appears.
I have listed the problems with your code below, here is a working code:
str = {'LLSQ fit: ' ...
'z = $\bar{a}_{1}$ + $a_2x$ + $a_3y$' ...
['$\bar{a}_{1}$ = ' sprintf('%5.2f', a1)] ...
['$a_2$ = ' sprintf('%5.2f', a2)] ...
['$a_3$ = ' sprintf('%5.2f', a3)]};
annotation('textbox', [0.5 0.8 0.3 0.08], 'interpreter','latex', 'String', str);
Problems with the original code
You have to wrap the whole latex
commands with $
sign:
This code does not give the desired output:
annotation('textbox', [.2 .4 .1 .1], 'interpreter','latex', 'String', 'a_2x');
But this one does:
annotation('textbox', [.2 .4 .1 .1], 'interpreter','latex', 'String', '$a_2x$');
You will loose some part of the string if you use sprintf
since it has another interpreter (there are workarounds for this, but I suggest concatenating strings as I did above)
sprintf('$\bar{a}_{1}$ = %5.2f', a1)
will return:
ar{a}_{1}$ = 1.00
which is not recognized by latex
. (\b
is interpreted as backspace in sprintf
and removes the vital $
sign.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With