フィルターのクリア

Simulink SDI Snapshot Command Missing Data

4 ビュー (過去 30 日間)
RIchard
RIchard 2023 年 10 月 9 日
コメント済み: RIchard 2023 年 10 月 24 日
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 Center および File ExchangeSources についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by