how to write a fraction in xlabel.
Show older comments
dear all, I want to write a fraction a over b in the xlabel. How to do that? thanks
if true
%
figure (1)
fig =figure(1);
plot(t,real(y)'-x')
title('Mutual inductance M at frequency of 0.159 GHz','FontSize',18,'FontWeight','bold')
xlabel ??????????????????????????????????????????????????????????????????????????????????????????
ylabel('Inductance (nH)','FontSize',18,'FontWeight','bold')
set(fig,'position',[500 300 800 600]);
grid on
end
3 Comments
hamed shorakaei
on 6 Oct 2017
Edited: Walter Roberson
on 12 Apr 2023
Use the following style:
xlabel('$\displaystyle\frac{W}{h}$','interpreter','latex')
Panagiotis Papias
on 5 Sep 2022
I wanted to take a moment and thank you for this comment, now I feel that is nicer latex being able to be used as an "add on" in Matlab.
Lars Abrahamsson
on 12 Apr 2023
I miss the possibility to write
xlabel('$\displaystyle\frac{\text{W}}{\text{h}}$','interpreter','latex')
for example. But that is not possible it seems. Mathematical font is not wanted for "Watt per hour" for example.
Accepted Answer
More Answers (1)
Reko Hynönen
on 18 Sep 2017
An old topic, but I've got an improved answer.
Star Strider's answer will work but it will look a bit silly. But like they suggest, you could use LaTeX interpreter instead.
Using LaTeX interpreter, you could accomplish this by writing:
xlabel('$\frac{a}{b}$','Interpreter','latex')
\frac{a}{b} is a LaTeX syntax for fractions. It will write 'a' to the numerator and 'b' to denominator. '$' symbols at the beginning and the end are necessary to interpret the expression in LaTeX Math mode, that interprets \frac correctly.
10 Comments
Viesturs Veckalns
on 26 Oct 2017
Edited: Viesturs Veckalns
on 26 Oct 2017
I am using
c_f4_3D = colorbar
c_f4_3D.Label.String = '$\frac{E}{K} [GeV]$'
c_f4_3D.Label.Interpreter = 'latex';
and get a warning:
Warning: Error updating Text.
String must have valid interpreter syntax:
$\frac{E}{K} [GeV]$
What is wrong?
Jaehong Jeong
on 14 Nov 2017
You should change the interpreter first before using the latex syntax ;) Just swap 2 lines, then the warning message will be gone.
Lars Abrahamsson
on 25 Aug 2020
I noticed that the LaTeX intepretor does not accept for example
$\frac{\text{m}^3}{s}$
Then I get this error message

And if I cannot use
\text
is has to be:
ylabel('Spill [$\frac{m^3}{s}$]','Interpreter','latex')
and then it will be rather ugly:

Any comments on this?
Simon Keegan
on 2 Feb 2021
@Lars Abrahamsson Have you found a solution for your problem? I am stuck with the same problem
Mikhail Skalyga
on 11 Jun 2022
Thank you!
Khalid Alshumayri
on 7 Sep 2022
Edited: Khalid Alshumayri
on 7 Sep 2022
Any update ? I want to use
xlabel(' sin($\frac{2\times\pi}{17}$) + 2\times\pi\times/17) ')
Possibly this —
xlabel(' sin($\frac{2\times\pi}{17}$) + $\frac{2\times\pi}{17}$ ', 'Interpreter','latex')
.
Lars Abrahamsson
on 12 Apr 2023
@Simon Keegan unfortunately no solution. I even forgot I commented on this thread earlier ...
Lars Abrahamsson
on 12 Apr 2023
@Simon Keegan Actually, I think I found something like a solution
xlabel('Discharge $\displaystyle \frac{\rm m^3}{\rm s}$', 'Interpreter','latex')

Simon Keegan
on 13 Apr 2023
Maybe I'll have a similiar case in future
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!