superscript/subscript in labels not working

I wanted to use superscripts for x or y axis labels by using commands like:
ylabel('e^t')
However, the result is simply e^t, no matter how many times I tried. The '\' function for greek letters does not work either. Can anyone tell me what is wrong with my Matlab?
Thank you, Woonsup

 採用された回答

MHN
MHN 2016 年 2 月 18 日

4 投票

x= 1:10;
y=2*x;
plot(x,y)
ylabel('e^t')
It works on Matlab R2014b, maybe the version that you are using does not support latex format.

5 件のコメント

MHN
MHN 2016 年 2 月 18 日
編集済み: MHN 2016 年 2 月 18 日
Try this one (it is an example from Matlab's documentation), if it does not work then the problem is your Matlab version. If it works, then you should change the interpreter to latex for your code.
x = linspace(0,3);
y = x.^2.*sin(x);
plot(x,y)
line([2,2],[0,2^2*sin(2)])
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(0.25,2.5,str,'Interpreter','latex')
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4])
Woonsup Choi
Woonsup Choi 2016 年 2 月 19 日
Can you tell me how to "change the interpreter to latex for your code"? The suggested method (str=...) worked, but it is not exactly what I wanted, because the result looks like an equation. I am using R2015a.
MHN
MHN 2016 年 2 月 19 日
編集済み: MHN 2016 年 2 月 19 日
If you are using R2015 I believe the default value is tex. Try this code:
x= 0:0.01:1;
y= exp(x);
plot(x,y)
ylabel('e^x', 'Interpreter','tex')
Woonsup Choi
Woonsup Choi 2016 年 2 月 24 日
This worked! Thank you.
thewordneverfound
thewordneverfound 2017 年 9 月 5 日
Extremely helpful! Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by