How do I add figure, scope and base workspace variables by Simulink Report API?

1 次查看(过去 30 天)
I have questions about Simulink Report Generator R2024a. After running a simulation using a set of Simulink models (consisting of multiple .slx files, .m files, and .mlx files), I would like to output the simulation conditions and results in a specified format as a report or summary table. I have reviewed the following page: 
https://jp.mathworks.com/help/rptgenext/ug/create-a-simulink-report-generator-report.html
Based on this, I have a few questions:
q1. Is it possible to include graphs generated by figures or the Data Inspector in the report?
q2. Is it possible to list variable names and their values (for variables defined in .m files in the base workspace) in a summary table?
q3. Is it possible to output both 1 and 2 in the same report?

采纳的回答

MathWorks Support Team
MathWorks Support Team 2025-12-16,0:00
In addition to the example you linked, the following link also gives an example of a MATLAB program that generates a more thorough report of a Simulink model:
https://www.mathworks.com/help/releases/R2024a/rptgenext/ug/generate-system-design-report-with-report-api.html
It doesn't include the exact information from your questions, but it gives some additional examples of what you can do with Simulink report generator methods.
Now for your questions:
1. You can include graphs generated by figures in a report with the mlreportgen.report.Figure reporter:
https://www.mathworks.com/help/rptgen/ug/mlreportgen.report.figure-class.html
You can create the Figure reporter with just the figure handle and then add it to the report/chapter/section:
figReporter = mlreportgen.report.Figure(f); % f is figure handle, or use f=gcf for current figure
append(rpt, figReporter);
For reporting the Data Inspector information, you can create a snapshot of the Data Inspector with the method Simulink.sdi.snapshot:
https://www.mathworks.com/help/simulink/slref/simulink.sdi.snapshot.html
This creates a MATLAB figure that displays the snapshot. You can then add the figure to the report using the method above.
Alternatively, you can use the simulink.sdi.report method:
https://www.mathworks.com/help/simulink/slref/simulink.sdi.report.html
Or create a report with the Data Inspector UI:
https://www.mathworks.com/help/simulink/ug/create-an-interactive-comparison-report.html
This will generate an HTML file separate from the report generated with Simulink report generator, but it provides more customization options than just the Simulink.sdi.snapshot.
2. The "Generate System Design Report" example linked above includes a section that summarizes variables used by Simulink blocks, including those defined in the base workspace. The code is defined in the "makeDesignDataChapter" function. Alternatively, to summarize all variables in the base MATLAB workspace, regardless of whether you are used by a Simulink block, you can use the MATLABVariableFinder and SummaryTable classes:
varFinder = mlreportgen.finder.MATLABVariableFinder(); % By default this searches the MATLAB base workspace for variables
varResults = find(varFinder);
varTable = mlreportgen.report.SummaryTable(varResults);
varTable.Properties = ["Name", "Class", "Value"];
append(rpt, varTable);
3. You can easily add the MATLAB figure graphs, Data Inspector snapshots, and the variable summary table to the same slreportgen.report.Report object, and they will be output in the same report. The full Data Inspector report is generated as a separate HTML file. You can add this file to the report using mlreportgen.dom.HTMLFile, but you may lose some formatting. Example:
sdiReportFile = "sdireports/mySdiReport.html"; % Change to whatever your file name is
htmlFileObj = mlreportgen.dom.HTMLFile(sdiReportFile);
append(rpt, htmlFileObj);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Reporting and Database Access 的更多信息

标签

尚未输入任何标签。

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by