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
dpb
2026년 6월 13일
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
2026년 7월 8일 9:32
dpb
2026년 7월 8일 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.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Reporting and Database Access에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!