如何在matlab图形标签中包含脚本字母

问题描述 投票:0回答:2

我想在Matlab图形的Y轴标签中包含一个脚本英文字母,例如

\mathscr{T}
。是否有捷径可寻?谢谢你。

matlab fonts latex matlab-figure tex
2个回答
5
投票

Matlab 的 LaTeX 解释器似乎无法识别

\mathscr
。但它接受
\mathcal
:

ylabel('$\mathcal{T}$','Interpreter','LaTeX','Fontsize',12)

0
投票

补充说明:如果在字符串中使用

sprintf
命令(用于输入某些变量的值),则需要再放置一个转义字符
\
,以便 MATLAB 识别
\mathcal{}
命令以及其他类似
\in{}
的命令。

x = 1:5;
y = sin(x);
plot(x, y);
% regular string does NOT need nother escape character
% xLabel = "t \in [1, 5], t \in \mathcal{N}";
% sprintf needs another escape character
xLabel = sprintf("t \\in [%d, %d], t \\in \\mathcal{N}", x(1), x(end)); 
xlabel(strcat("$", xLabel, "$"), 'Interpreter', 'latex');
yLabel = "sin(t)";
ylabel(strcat("$", yLabel, "$"), 'Interpreter', 'latex');
titleStr = strcat("$\sin(t)$", " for ",  "$", xLabel, "$");
title(titleStr, 'Interpreter', 'latex')
© www.soinside.com 2019 - 2024. All rights reserved.