Matlab情节中的希腊字母

Matlab情节中的希腊字母,matlab,matlab-figure,Matlab,Matlab Figure,我已经在Matlab中创建了一个绘图,现在我想用以下命令添加一个图例: legend({'Pos1', 'Pos2', 'Pos3', '\alpha Pos4'}, 'Location', 'northeast', 'Interpreter', 'latex', 'fontsize', 22); legend('boxoff') 问题是\alpha没有转换成希腊字母。如果我使用花括号{},那么它可以工作,但我需要它们,因为我只想标记前四行 我怎样才能得到希腊字母alpha?你忘了$ lege

我已经在Matlab中创建了一个绘图,现在我想用以下命令添加一个图例:

legend({'Pos1', 'Pos2', 'Pos3', '\alpha Pos4'}, 'Location', 'northeast', 'Interpreter', 'latex', 'fontsize', 22);
legend('boxoff')
问题是
\alpha
没有转换成希腊字母。如果我使用花括号{},那么它可以工作,但我需要它们,因为我只想标记前四行


我怎样才能得到希腊字母alpha?

你忘了
$

legend({'Pos1', 'Pos2', 'Pos3', '$\alpha$ Pos4'}, 'Location', 'northeast', 'Interpreter', 'latex', 'fontsize', 22);
我想继续丹尼尔的回答,并解释一些细节

没有
{}
如果未在单元格数组中指定图例条目,则直接调用
图例
时只能使用属性
位置
方向
。如果存在其他特性,则将其解释为图例条目。这意味着
解释器
文本大小
,其值将是图例条目。回复Adiel关于为什么它显然在没有
{}
的情况下工作的评论:它实际上不工作,它甚至发出警告,间接地是因为上述原因

旁注:根据语法,必须在属性之前提供图例条目。尽管如此,它确实可以按任何顺序工作,但我不建议使用这种未记录的行为

选择地块 您提到必须使用
{}
仅选择前四行。这是不正确的,因为默认情况下,
图例
选择前N个绘图。问题是这些属性的解释如上所述。要选择特定打印,可以使用打印控制柄省去第二个打印:

legend([ph1,ph3,ph4,ph5], 'Pos1', 'Pos3', 'Pos4', 'Pos5');
使用其他属性 为了能够在调用
图例
时直接使用其他属性,可以将图例条目作为单元格数组提供。这将使条目与属性的名称-值对解耦。例如,更改字体大小:

legend({'Pos1', 'Pos2', 'Pos3', 'Pos4'}, 'Fontsize', 22);
另一种可能是使用句柄设置其他属性,而不使用单元格数组:

l = legend('Pos1', 'Pos2', 'Pos3', 'Pos4');
set(l, 'Fontsize', 22);     % using the set-function
l.FontSize = 22;            % object oriented
latex
-解释器 如果将
解释器
设置为
latex
,则图例项的所有内容都需要可由latex编译。这意味着
\alpha
不能在数学环境之外使用。要在LaTeX中添加内联数学表达式,可以使用
$
-符号将其括起来。因此,
$\alpha$
的工作原理与Daniel的回答中提到的一样。使用
tex
-解释器,Matlab使用tex标记的一个子集,并自动处理支持的特殊字符,因此在不使用
latex
IntrMeter时,不需要
$…$


建议
  • 不要忘记
    $
    -符号
  • 在调用
    legend
    中处理特定的绘图
  • 使用单元格数组并直接设置调用
    legend
    中的所有属性
  • 使用
    可以将长线拆分为几行
例如:

legend([ph1,ph3,ph4,ph5], ...
    {'Pos $\alpha$', 'Pos $\beta$', 'Pos $\gamma$', 'Pos  $\delta$'}, ...
    'Location', 'northeast', 'Interpreter', 'latex', 'FontSize', 22);
以下是示例的完整代码:

因此:


何时需要
$
?为什么没有
{}
它就可以工作?
figure; hold on;
ph1 = plot(0,-1,'*'); ph2 = plot(0,-2,'*');
ph3 = plot(0,-3,'*'); ph4 = plot(0,-4,'*');
ph5 = plot(0,-5,'*'); ph6 = plot(0,-6,'*');
legend([ph1,ph3,ph4,ph5], ...
    {'Pos $\alpha$', 'Pos $\beta$', 'Pos $\gamma$', 'Pos  $\delta$'}, ...
    'Location', 'northeast', 'Interpreter', 'latex', 'FontSize', 22);