可以动态地将部分添加到Matlab发布脚本吗? [英] Can one dynamically add sections to a matlab publish script?
问题描述
我有一个matlab脚本,我想在我的matlab发布中动态创建节.
I have a matlab script, where I would like to dynamically create sections in my matlab publish.
目前,我知道创建分节符的唯一方法是将这样的代码放入我的脚本中:
At present, the only way I know to create a section break, is to put code like this in my script:
%% This is a section break
我想在自己的脚本上运行发布,并且将分节符添加为发布的一部分.例如.说我有以下脚本:
I'd like to run publish on my script, and have the section breaks get added as part of the publish. For instance. Say I had the following script:
breaks(1).name = 'This is section break 1.';
breaks(2).name = 'This is section break 2.';
for ix = 1 : numel(breaks)
functionThatInsertsSectionBreakTitle(breaks(ix).name);
fprintf('Some random processing associated with break %d.\n', ix);
end
我想在该脚本上调用发布,最后得到一个看起来像这样的文档:
I would like to call publish on that script, and end up with a document that looks something like:
这是分节符1.
一些与中断1相关的随机处理.
Some random processing associated with break 1.
这是分节符2.
与中断2相关的一些随机处理.
Some random processing associated with break 2.
很显然,我可以通过编写脚本来完成此任务,该脚本编写的脚本随后将通过发布执行.我希望有一些更直接的东西.我知道报告生成工具箱,我希望它可以干净地处理这种情况.或者,如果新版本(自R2016a起)在线脚本处理此用例,这也是一个很好的答案.
Obviously I could do this by writing a script that writes a script that then gets executed by publish. I was hoping for something a bit more direct. Am aware of the report generation toolbox, which I would hope would cleanly handle this type of scenario. Alternatively, if the new (as of R2016a) Live Script handles this use case, that's a fine answer as well.
推荐答案
解决此问题的一种方法是在命令输出中显示html代码(已记录为
One way to address this problem is by displaying html code in the command output (documented here).
在您的示例中,代码如下所示:
In your example, the code would look like this:
breaks(1).name = 'This is section break 1.';
breaks(2).name = 'This is section break 2.';
for ix = 1 : numel(breaks)
disp(['<html><h2>' breaks(ix).name '</h2></html>']);
fprintf('Some random processing associated with break %d.\n', ix);
end
当您要使结果以自定义布局(例如表格)显示时,此功能非常有用.而且它避免了获得Matlab报告生成器许可证的需要...
This is incredibly useful when you want to get results to be displayed with a custom layout, such as a table. And it avoids the need of having a Matlab Report Generator license...
这篇关于可以动态地将部分添加到Matlab发布脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!