Report Generator: Adding images

7 次查看(过去 30 天)
Hi! I'm trying to generate a report from a Simulink Model programatically and I encountered 2 issues.
  1. If I want to add an image to the model (e.g. as an annotation), how can i add it in the report afterwards?
  2. 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!

采纳的回答

Abhishek
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 个)

类别

Help CenterFile Exchange 中查找有关 Create Report Programs Using the Report API 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by