- ‘AnnotationFinder’: https://www.mathworks.com/help/releases/R2024b/rptgenext/ug/slreportgen.finder.annotationfinder-class.html
- MATLAB Report Generator: https://www.mathworks.com/help/releases/R2024b/rptgen/index.html
Report Generator: Adding images
13 ビュー (過去 30 日間)
古いコメントを表示
Hi! I'm trying to generate a report from a Simulink Model programatically and I encountered 2 issues.
- If I want to add an image to the model (e.g. as an annotation), how can i add it in the report afterwards?
- I am trying to get an image of a Stateflow Chart (with all the states visible). I tried using this method to get inside the Stateflow Chart:
st = find(sfroot,"-isa","Stateflow.State");
but I can only get a snapshot of the chart box.
Are there any solutions?
Thank you!
0 件のコメント
採用された回答
Abhishek
2025 年 6 月 26 日
As far as I know, Simulink does not support embedding external image files (such as PNG or JPEG) directly as part of an annotation in the model. Therefore, image annotations cannot be extracted automatically by tools like ‘AnnotationFinder’.
A recommended workaround is to manually store the image file in your project directory and then programmatically include it in the report using the Report Generator:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('SimulinkModelReport', 'pdf');
add(rpt, TitlePage('Title','Simulink Report'));
add(rpt, TableOfContents);
img = Image('path_to_image.png');
img.Style = {ScaleToFit(true)};
add(rpt, img);
close(rpt);
rptview(rpt);
To capture the full image of a Stateflow Chart, the ‘Stateflow.State’ object alone might not be sufficient. Instead, you can use the ‘print’ function on the chart subsystem to export the entire chart area. You can take reference from this code, wherein I tried loading a sample model, named ‘model_sample’, and a chart, that is present in the current working directory, named ‘model_chart’:
model = 'model_sample ';
chartPath = [model, 'model_chart'];
load_system(model);
open_system(chartPath);
set_param(chartPath, 'ZoomFactor', 'FitSystem');
print(['-s', chartPath], '-dpng', '-r300', 'stateflow_chart.png');
The above code will export the image, having the name ‘stateflow_chart.png’ in the working directory.
For more detailed instruction, you can refer to the official documentation of MATLAB:
Hope this helps.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!