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

조회 수: 5 (최근 30일)
Steven
Steven 2022년 1월 18일
답변: Akanksha 2025년 6월 22일
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.

답변 (1개)

Akanksha
Akanksha 2025년 6월 22일
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!

카테고리

Help CenterFile Exchange에서 Simulink Report Generator에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by