How to include DOC contents in the report generated by Simulink Automatically

4 views (last 30 days)
We have software written in Simulink model and would like to add some information in DOC blocks along with other Simulink blocks in different layers. Is there a way to generate the Reports showing the contents of DOC blocks automatally. I can generate the report but it will not show the contents of DOC in it. Thank you.

Answers (1)

Akanksha
Akanksha on 22 Jun 2025
Hey Steven,
The contents of Simulink DocBlock blocks can be included in automatically generated reports using the Simulink Report Generator along with the MATLAB Report API. Here's how to achieve it:
Use the Report API – The slreportgen.report.DocBlock class is designed to pull content from DocBlocks and include it in your report.
Find the DocBlocks – Use slreportgen.finder.BlockFinder and set the MaskType to 'DocBlock' to locate them in your model.
Add Them to the Report – Loop through the found blocks and use the add method to include them in your report.
Here's a simplified version of the code from the official MathWorks example :
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
model = 'your_model_name';
load_system(model);
rpt = slreportgen.report.Report('MyReport','docx');
rpt.CompileModelBeforeReporting = false;
add(rpt, TitlePage('Title', 'Model Documentation'));
add(rpt, TableOfContents);
finder = SystemDiagramFinder(model);
for system = find(finder)
ch = Chapter('Title', sprintf('System %s', system.Name));
docBlockFinder = BlockFinder(system);
docBlockFinder.Properties = {'MaskType', 'DocBlock'};
results = find(docBlockFinder);
if ~isempty(results)
add(ch, results);
else
add(ch, "This system does not have documentation.");
end
add(rpt, ch);
end
close(rpt);
close_system(model);
rptview(rpt);
PFA the official MathWorks documentation for further information:
Hope this helps!

Categories

Find more on Simulink Report Generator in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!