Making screenshots via batch

I want to make a lot of screenshots via batch from a couple of Simulink Data Inspector timetable plots and graphical figures.
For this I am using the following code:
(extracted and anonymized from functions so please don't bother too much on small errors/missings, you get the point. This is the SDI screenshot example only, but the issue is basically the same for for example gps figure screenshots)
Open and populate SDI
Simulink.sdi.view;
Simulink.sdi.clear;
sdiRun = Simulink.sdi.Run.create;
sdiRun.Name = "Test";
sdiRun.Description = "Test";
add(sdiRun, "vars", tt);
Simulink.sdi.setSubPlotLayout(4,1);
parentSig = sdiRun.getSignalsByName('Msg1');
sdiSig = parentSig.Children(matches({parentSig.Children.Name}, 'Sig1'));
sdiSig.LineColor = validatecolor('cyan');
plotOnSubPlot(sdiSig, subPlot, 1, true);
create and save the screenshot
f = Simulink.sdi.snapshot('Filename', file);
exportgraphics(f, file, 'Resolution', 300);
close(f);
Simulink.sdi.close();
This works most of the time really bad. The graphics are not fully rendered, aka the SDI only displays incomplete curves, curves not always fitting to subplot, blank windows, only partial drawn subplot windows (aka graphics artefacts) etc.
Same for figures where for example I plot a GPS track and want to use 'geobasemap streets'
Questions:
  • How do I make sure the script waits until the rendering is complete (SDI or figures) before continuing and actually performing the screenshots?
  • How do I ensure/test if rendering succeeded or got stuck/failed/whatsoever?
  • How do I request/force the SDI to autozoom/fit all signals to their subplots?
  • Why do I have to pass a file to Simulink.sdi.snapshot()? No file is saved when I do this. I have to actually use exportgraphics() to get something written to disk.
Thanks for your support.

댓글 수: 1

dpb
dpb 2026년 6월 13일 13:58
I don't have Simulink so no direct knowledge, but I'd suggest a drawnow and a pause() might help.
You may need to submit this to Mathworks as an official support request at <Product Support Page>
When doing so, you'll need to create a minimusm working example to submit with all data files and no syntax or other warts to confuse issues.

댓글을 달려면 로그인하십시오.

답변 (0개)

제품

릴리스

R2024b

태그

질문:

2026년 6월 12일 8:25

댓글:

dpb
2026년 6월 13일 13:58

Community Treasure Hunt

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

Start Hunting!

Translated by