Writing legends for MATLAB figures with subscripts

20 次查看(过去 30 天)
What is the solution for writing legends for MATLAB figures with subscripts?

采纳的回答

Epsilon
Epsilon 2024-9-11
编辑:Epsilon 2024-9-11
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 个评论
Milad
Milad 2024-9-11
thanks. good solution.
How to use a special character like µ?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by