Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB:将LaTeX字符与Axis标题中的数据格式相结合_Matlab_Latex - Fatal编程技术网

MATLAB:将LaTeX字符与Axis标题中的数据格式相结合

MATLAB:将LaTeX字符与Axis标题中的数据格式相结合,matlab,latex,Matlab,Latex,我试图找出是否有一种方法可以让我通过TeX解释器将符号和数据输入组合成一个单独的字符串作为轴标题 例如,我当前的代码如下所示: figure axHandle = axes; appleTrees = 4; s = sprintf( ... 'Apples vs Acres\nNumber of Apples Trees $\alpha = %2.0f$', appleTrees); title(axHandle,s,'Interpreter','LaTeX') 我明白这是行不通的,但

我试图找出是否有一种方法可以让我通过TeX解释器将符号和数据输入组合成一个单独的字符串作为轴标题

例如,我当前的代码如下所示:

figure
axHandle = axes;
appleTrees = 4;
s = sprintf( ...
    'Apples vs Acres\nNumber of Apples Trees $\alpha = %2.0f$', appleTrees);
title(axHandle,s,'Interpreter','LaTeX')
我明白这是行不通的,但我认为它传达了我所要做的

sprintf导致以下消息:

Warning: Control Character '\l' is not valid. 
See 'doc sprintf' for control characters valid in the format string.

我可以抛弃sprintf,只使用引号,但这样我就失去了数据格式化/文本格式化功能。

在Matlab中为某些函数格式化字符串时,反斜杠
\
是一个特殊字符<代码>sprintf就是其中之一。要编写反斜杠,请改用
\\
。是其他特殊字符的列表,以及它们的书写方式

在您的情况下,请使用以下行:

s = sprintf( ...
    'Apples vs Acres\nNumber of Apples Trees $\\alpha = %2.0f$', appleTrees);

很高兴你赢了我几秒钟:)谢谢你的帮助!您还可以向我解释如何将结果标题文本居中吗?请尝试使用以下两个框:
\\makebox[10in][c]{Apples vs Acres}\n\\makebox[10in][c]{苹果树的数量$\\alpha=%2.0f$}