Simulink SDI Snapshot Command Missing Data

3 次查看(过去 30 天)
So the title kind of says it all. I am trying to run a simulink model and take snapshot of the SDI via the API (see command below). I am trying to plot ~15 signals spread across 9 subplots and cannot share the actual dataset
Simulink.sdi.snapshot('from','opened','to','file','filename','testFig.png')
Every time I run it, the 'testFig.png' is different with a different set of signals names show with or without the associated data series.
Does anyone know how long I should pause the program between the final plotting command and the saving command?

采纳的回答

Yash Sharma
Yash Sharma 2023-10-23
Hi Richard,
I understand that you want to take snapshot of a plot with 15 signals spread across 9 subplots, to ensure that the Simulink Data Inspector (SDI) has enough time to capture the desired signals and generate a consistent snapshot, you can introduce a delay or pause before taking the snapshot. The duration of the pause may vary depending on the complexity of your model and the time it takes for the signals to stabilize. Here are a few suggestions:
  • Use a fixed delay: Try adding a fixed delay using the pause function before taking the snapshot. Start with a conservative delay, such as 1-2 seconds, and adjust it as needed. For example:
% Plotting commands
pause(2); % Delay for 2 seconds
Simulink.sdi.snapshot('from', 'opened', 'to', 'file', 'filename','testFig.png');
  • Use a dynamic delay: You can monitor the signals you are interested in and wait until they stabilize or reach a specific condition before taking the snapshot.
while ~isStable()
pause(0.1); % Delay for 0.1 seconds
end
Simulink.sdi.snapshot('from', 'opened', 'to', 'file', 'filename', 'testFig.png');
function stable = isStable()
% Check if the signals have stabilized or reached a specific condition
% Return true if stable, false otherwise
end
  • Use a callback function: If you have access to the Simulink model, you can use a callback function to trigger the snapshot after a specific event occurs, like when a model stops its execution.
function snapshotCallback(block, event)
Simulink.sdi.snapshot('from', 'opened', 'to', 'file', 'filename', 'testFig.png');
end
% Configure the callback for a specific event (e.g., simulation time)
set_param('model_name', StopFcn, snapshotCallback);
Please find links to below documentation which I believe will help you for further reference:
Hope this helps!
  1 个评论
RIchard
RIchard 2023-10-24
The pause one works most of the time. The rest of your answer bypasses my question actually. I realized I didn't state the question very well to begin with so that's on me.
Basically, my computer takes some indeterminate amount of time to physically draw the plots on screen. One can take the snapshot before it is finished drawing and capture the exact image on screen (including the spinning wheel in upper right corner). Is there a way to query the system to know when it has finish drawing to the screen?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by