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.

3 comentarios

dpb
dpb el 13 de Jun. de 2026
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.
Marcus
Marcus el 8 de Jul. de 2026 a las 9:32
Drawnow and pause don't really help. As of now as a workaround I added a manual step and removed the closure of the sdi window. If the SDI window is kept open it usually works. Not really satisfying but sufficient for the moment.
Eventually if pain rises again I'll open a ticket.
dpb
dpb el 8 de Jul. de 2026 a las 14:44
Sounds like a reasonable stopgap approach; glad to hear you found something that at least suffices. It seems as though the facility to be able to do something of the sort in batch mode is a reasonable user expectation that would be worthy of enhancement suggestion anyway.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Reporting and Database Access en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Etiquetas

Preguntada:

el 12 de Jun. de 2026

Comentada:

dpb
el 8 de Jul. de 2026 a las 14:44

Community Treasure Hunt

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

Start Hunting!

Translated by