我想在Matlab图形的Y轴标签中包含一个脚本英文字母,例如
\mathscr{T}
。是否有捷径可寻?谢谢你。
Matlab 的 LaTeX 解释器似乎无法识别
\mathscr
。但它接受\mathcal
:
ylabel('$\mathcal{T}$','Interpreter','LaTeX','Fontsize',12)
补充说明:如果在字符串中使用
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')