Writing legends for MATLAB figures with subscripts

What is the solution for writing legends for MATLAB figures with subscripts?

 採用された回答

Epsilon
Epsilon 2024 年 9 月 11 日
編集済み: Epsilon 2024 年 9 月 11 日

0 投票

Hi Milad,
You can create legends with subscripts by using the LaTeX interpreter. Use the underscore character _ to denote subscripts, and set the interpreter to 'latex'.
Attaching a small code for reference:
x = linspace(0, 2*pi, 100);
y1 = sin(x);
y2 = cos(x);
plot(x, y1, x, y2);
% Create a legend with subscripts
legend({'$y_1 = \sin(x)$', '$y_2 = \cos(x)$'}, 'Interpreter', 'latex');
You can also refer to the documentation Add legend to axes - MATLAB legend (mathworks.com) for further reference.

3 件のコメント

Voss
Voss 2024 年 9 月 11 日
編集済み: Voss 2024 年 9 月 11 日
@Milad: FYI, Interpreters 'tex' and 'latex' both support subscripts using the underscore character.
'tex' is the default interpreter.
plot(1:10)
legend('a_1')
Milad
Milad 2024 年 9 月 11 日
thanks. good solution.
How to use a special character like µ?
Stephen23
Stephen23 2024 年 9 月 11 日
編集済み: Stephen23 2024 年 9 月 11 日
"How to use a special character like µ?"
Exactly as the documenation states, use LaTex markup:
\mu

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2023a

質問済み:

2024 年 9 月 11 日

編集済み:

2024 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by