Report Generator: Add Notes in Report Generator & Add Live Script to Report

6 visualizzazioni (ultimi 30 giorni)
Hello,
i am sitting on two problems regarding the Report Generator. (MATLAB 2020a)
Add Notes to report with the Report Generator
For documenting Code I want to use the Notes Function (Modeling -> System Design -> Notes). Currently I add the Notes to a Reporth with the matlab report class. (A short excerpt of my script)
rpt = slreportgen.report.Report("Name","docx");
open(rpt);
finder = DiagramFinder("SimulinkModel");
ch = Chapter("Diagram Report");
while hasNext(finder)
system = next(finder);
sc = Section("Title",system.Name);
notes = Notes(system);
add(sc,notes);
add(ch,sc)
end
add(rpt,ch);
Is it possible to use the Report Generator / Report Explorer to add System Notes to a report, as there is no function provided?
Add Live Script to report
For equations and theory I use Simulink Live Scripts. I want them in an extra chapter of my report. Is it possible to add Live Scripts to a Report? If this is not possible directly, maybe i can convert the live script to a .docx file and then add id to a existing word report?
Thank you and best regards

Risposte (1)

Sanchari
Sanchari il 22 Mag 2024
Hello Alexander,
The first use-case that you have described is available as a feature in R2024a. So please consider upgrading to this version and check out the following MathWorks Documentation on “Report Model Notes”, https://www.mathworks.com/help/rptgenext/ug/report_model_notes.html.
However, given that you are using MATLAB R2020a, since direct support for some features might not exist, there are possible solutions and workarounds for both issues:
Adding System Notes to a Report:
Currently, the script-based approach is a good strategy. The method of iterating over systems in a Simulink model and adding notes to the report is valid. However, if “Notes(system)” isn't directly fetching the notes because it's not a built-in function for this purpose, you might need to manually fetch and format the notes from each system. Here's an enhanced approach:
  1. Fetch System Notes: You'll need to access the notes from each system manually. If the system notes are stored in a block or as a parameter, you'll have to fetch them using “get_param” or similar functions.
  2. Format and Add Notes: Once you have the notes, format them as text or paragraphs using “mlreportgen.dom” classes and then add them to your section.
Adding Live Scripts to a Report:
For incorporating MATLAB Live Scripts “.MLX files” into your report, converting the live script to a format that's compatible with report (e.g., PDF, DOCX) and then including it is a practical approach. MATLAB doesn't provide direct support for embedding “.MLX” content into reports generated by “slreportgen.report.Report” in R2020a so here's how you can convert and include a live script:
1. Convert Live Script to PDF: First, convert your “.MLX” file to a “.PDF”. While MATLAB R2020a doesn't have a direct function in the Live Editor to export to “DOCX”, you can use “PDF” as an intermediary. Here’s the code snippet:
matlab.internal.liveeditor.openAndConvert('yourScript.mlx', 'yourScript.pdf');
2. Include PDF in Report: Directly embedding a “.PDF” into a “.DOCX” report isn't straightforward. As a workaround, you can include a link in the report that points to the PDF file stored locally or hosted online. Here’s the code snippet:
link = mlreportgen.dom.ExternalLink('path/to/yourScript.pdf', 'See the Live Script here');
add(sc, link);
Please refer to the following references to know further about:
  1. Create Report Programs (MathWorks Documentation): https://www.mathworks.com/help/rptgenext/interactive-report-creation.html
  2. Simulink Report Generator Task Examples: https://www.mathworks.com/help/rptgenext/simulink-report-generator-task-examples.html
  3. Report Model Notes (MathWorks Documentation): https://www.mathworks.com/help/rptgenext/ug/report_model_notes.html
  4. MATLAB Report Generator – Custom Report Using Report API (File Exchange): https://www.mathworks.com/matlabcentral/fileexchange/71896-matlab-report-generator-custom-report-using-report-api?s_tid=answers_rc2-2_p5_MLT
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by