9

我正在使用 MATLAB 脚本来调整机器上的控制系统。调整完成后,我想要一份包含文本(尤其是序列号、日期/时间和调整期间确定的值)和图,尤其是传递函数的报告。

你有什么建议?

我使用的任何解决方案都应该与 MATLAB 编译器兼容,这样我就可以将我的解决方案分发给现场工程师团队。

理想情况下,报告将是 PDF 文档。

MATLAB 报告生成器似乎不是正确的产品,因为我似乎必须将我的脚本分成小块并将它们嵌入到报告模板中。如果绘图看起来不正确,我的脚本包含用户干预和更改值或拒绝调整的机会,我的直觉是,如果代码从报告生成器运行,这将很困难。另外,如果代码结构由报告模板的要求决定,我担心代码结构和可维护性会丢失。

如果我的假设是错误的,请发表评论。

更新

我现在已经切换到使用 r2016b 版本的 MATLAB 报告生成器,它对我的​​编译代码用户来说工作得很好。不幸的是,这意味着拥有 MATLAB 许可证的同事也需要购买报告生成器,才能使用我的脚本工具。

4

4 回答 4

4

As the MATLAB Report Generator's development manager, I am concerned that this question may leave the wrong impression about the Report Generator's capabilities.

For one thing, the Report Generator does not require you to break a script up into little pieces and run them inside a template. You can do this if you choose and in some circumstances, it makes sense, but it is not a requirement. In fact, many Report Generator applications use a MATLAB script or program to interact with a user, generate data in the MATLAB workspace, and as a final step, generate a report from the workspace data.

Moreover, as of the R2014b version, the MATLAB Report Generator comes with a document generation API, called the DOM API, that allows you to embed document generation statements in a MATLAB program. For example, you can programmatically create a document object, add and format text, paragraphs, tables, images, lists, and subdocuments, and output Microsoft Word, HTML, or PDF output, depending on the output type you select. You can even programmatically fill in the blanks in forms that you create, using Word or an HTML editor.

The API runs on Windows, Linux, and Mac platforms and generates Word and HTML output on all three, without the use of Word. On Windows, it uses Word under the hood to produce PDF output from the Word documents that it generates.

The latest release of the MATLAB Report Generator introduces a PowerPoint API with capabilities similar to the DOM API. If you need to include report generation in your MATLAB application, please don't rule out the MATLAB Report Generator based on past impressions. You may be surprised at just how powerful it has become.

于 2015-06-15T16:00:11.953 回答
3

I've done this quite a bit. You're right that MATLAB Report Generator is typically not a great solution. @Max suggests the right approach (automating Word through its COM interface), but I'd add a few extra comments and tips, based on my experiences.

  1. Remember that if you're going with this solution, you are depending that your end-users will be running Windows, and have a copy of Office on their machine. If you want to ultimately produce a PDF report, that will need to be Office 2010 or above.
  2. I would bet that you'll find it easier to automate the report generation in Excel rather than Word. Given that you're producing a report from MATLAB, you'll likely be wanting quite a lot of things in tables of numbers, which are easier to lay out in Excel.
  3. If you are going to do it in Word, the easiest way is to first (without MATLAB) create a template .doc/.docx file, which contains any generic text that will be the same for all reports and blank tables for any information. Turn on track changes, and insert empty comments at each point that you will be filling in information. Then within your report creation routine in MATLAB, connect to Word and iterate through each comment, replacing it with whatever data you wish.
  4. If you are learning to automate Excel from MATLAB, this page from the Excel Interop documentation is really helpful. There's an equivalent one for Word.
  5. Unlike @Max, I've never had good results by saving figures to an .emf file and then inserting them. In theory that does preserve editability, but I've never found that valuable. Instead, get the figure looking right (and the right size) in MATLAB, then copy it to the clipboard with print(figHandle, 'dbitmap') and paste to Excel with Worksheet.Range('A1').PasteSpecial.
  6. To save as a PDF, use Workbook.ExportAsFixedFormat('xlTypePDF', pathToOutputFile).

Hope that helps!

于 2012-11-22T16:34:32.563 回答
2

我认为您对报告生成器的看法是正确的。

在我看来,最快/最简单的方法是在 html 文档中生成报告。为此,您只需要数字并编写一个文本文件,转换应该是微不足道的。

非常相似的方法是创建一个 Latex 文件。然后从中创建一个 pdf - 尽管为此您需要在部署的机器上安装乳胶。

Lastly you could use the good integration of Java in Matlab. There are several libraries you could use - like this. But I wonder if all the complication will be worth it.

于 2012-11-22T10:14:11.727 回答
1

您是否考虑过通过 ActiveX 界面驱动 Microsoft Word?我已经在编译的 Matlab 程序中完成了这项工作,并且效果很好。查看 Matlab 帮助actxserver(): 您要创建的对象是类型Word.Application

编辑添加:要将数字放入文档,使用-dmeta参数将它们保存为 .emf 文件print(),然后将它们添加到文档中,如下所示:

 WordServer.Selection.InlineShapes.AddPicture(fileName);
于 2012-11-22T10:12:05.537 回答