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
Matlab 如何从变量手动输出发布内容_Matlab_Latex_Publishing - Fatal编程技术网

Matlab 如何从变量手动输出发布内容

Matlab 如何从变量手动输出发布内容,matlab,latex,publishing,Matlab,Latex,Publishing,当使用MATLAB的发布功能时,它通常只发布%符号或函数输出之后的内容。但是,是否有任何命令可以获取变量并将其值拼接到文本中,甚至可能从保存字符串的MATLAB变量创建LaTeX公式?以下是呈现LaTeX公式的示例(一个在注释中硬编码,另一个作为字符串存储在变量中) 以下是文件以HTML形式发布时的外观: 您可以将最后一个代码包装到一个helper函数render\u latex\u string(str)中,并从不同的位置调用它。使用工作区中的变量 使用带有html编码字符串的disp()发

当使用MATLAB的发布功能时,它通常只发布%符号或函数输出之后的内容。但是,是否有任何命令可以获取变量并将其值拼接到文本中,甚至可能从保存字符串的MATLAB变量创建LaTeX公式?

以下是呈现LaTeX公式的示例(一个在注释中硬编码,另一个作为字符串存储在变量中)

以下是文件以HTML形式发布时的外观:

您可以将最后一个代码包装到一个helper函数
render\u latex\u string(str)
中,并从不同的位置调用它。

使用工作区中的变量 使用带有html编码字符串的
disp()
发布到html时,会将行添加到输出中(不使用代码输出的格式)

比如说

str = sprintf('some value: %f from the workspace',variable)
disp(['<html>',str,'</html>'])
str=sprintf('some value:%f from the workspace',variable)
disp(['',str,'')
注:

  • 这是相当敏感的,你可能需要添加不可见的部分之间的休息 以这种方式生成的代码输出和行
  • 添加段落标记有助于改进格式
  • 遗憾的是(据我所知),这些行上没有使用发布降价解释器,它们被“注入”到输出中,因此latex方程将无法工作
代码
%%HTML选项
%此选项仅适用于HTML输出。。。
a=1;
str=['当前a值为',num2str(a)];
%%%
% 
%使用带有HTML标记的| disp |函数发布到HTML时
%围绕字符串可以允许工作空间变量出现在
%文本。
% 
%例如,下面的行是通过计算代码创建的,它不是
%m文件中的注释
% 
disp(['',str'

']); %%更改值 %现在如果我们把a改成2。。。 a=2,str=[‘a的新值为’,num2str(a)]; %% %重新运行类似的代码应该会显示更新后的值 disp(['',str'

']))
输出 上面的代码生成以下内容:


非常适合内容,但我似乎无法使用LaTeX。抱歉,可能没有给予足够的关注或正确的工作方式,但第三个要点是为了涵盖这一点而添加的。。。基本上,据我所知,以这种方式生成的文本不会被publish解释,而只是“注入”到html文档中
str = sprintf('some value: %f from the workspace',variable)
disp(['<html>',str,'</html>'])
%% HTML option 
% This option is anly available with HTML output...
a=1;
str = ['The current value of a is ', num2str(a)];

%%%
% 
% When publishing to HTML using the |disp| function with HTML tags 
% surrounding the string can allow workspace variables to appear within 
% text.
% 
% For example the following line is created by evaluating code, it is not a
% comment in the m-file
% 
disp(['<html><p>',str,'</p></html>']);

%% Changing the value
% Now if we change a to 2...
a=2,str = ['The new value of a is ', num2str(a)];
%%
% Re-runing a similar code should show the updated value
disp(['<html><p>',str,'</p></html>'])