如何从变量手动输出发布内容 [英] How to manually output publishing content from a variable
本文介绍了如何从变量手动输出发布内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当使用MATLAB的发布功能时,它通常只会出现在%符号或函数输出之后。但是,有没有任何命令可以使用变量,并将其值拼接到文本中,甚至可以从包含字符串的MATLAB变量创建LaTeX公式?
When using the Publish feature of MATLAB, it typically publishes only what comes after the % signs or the function output. However, is there any command to take a variable and splice its value into text, possibly even creating LaTeX formulae from a MATLAB variable that holds a character string?
推荐答案
使用 disp()
/ code>与html编码的字符串将添加行到输出(不使用格式化的代码输出)。
To use variables from the workspace
when Publishing to html using disp()
with a html encoded string will add the lines to the output (without using the formatting for code output).
例如
str = sprintf('some value: %f from the workspace',variable)
disp(['<html>',str,'</html>'])
注意:
- 这是非常敏感的,您可能需要在
代码输出和以这种方式生成的行。 - 添加段落标签对于改进格式是非常有用的
- 令人遗憾的是,我不知道发布标记解释器在这些行上,它们是注入到输出中,因此乳胶方程式将不起作用。
- It is quite sensitive and you may need to add invisible section breaks between code output and lines produced in this way.
- Adding paragraph tags is useful to improve formatting
- Sadly (to my knowledge) the publishing markdown interpreter is not used on these lines, they are "injected" into the output, therefore latex equations will not work.
%% 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>'])
输出
上面的代码生成以下内容:
Output
The code above generates the following:
这篇关于如何从变量手动输出发布内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文