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:
- ‘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
Hope this helps.
