Simulink SDI Snapshot Command Missing Data
1 view (last 30 days)
Show older comments
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?
1 Comment
Richard Hopple
on 19 Mar 2025
Edited: Richard Hopple
on 19 Mar 2025
For reason unknown to me, the accepted answer actually doesn't answer the question and for reasons unknown to me, I cannot actually edit my original post...
Accepted Answer
Yash Sharma
on 23 Oct 2023
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:
- Pause: https://in.mathworks.com/help/matlab/ref/pause.html
- Investigate signal values: https://in.mathworks.com/help/simulink/ug/signal-values.html
- Model callbacks: https://in.mathworks.com/help/simulink/ug/model-callbacks.html
- Set_param: https://in.mathworks.com/help/simulink/slref/set_param.html
- Set param with callback: https://in.mathworks.com/matlabcentral/answers/19135-set_param-and-callback-argument
Hope this helps!
More Answers (0)
See Also
Categories
Find more on Interactive Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!