How can I create new runs & discard data from SDI while live streaming real-time signals from my Speedgoat target?

20 views (last 30 days)
I am doing iterative experiments with my Speedgoat hardware where I would like to start and stop live streaming to monitor signals in MATLAB during the simulation. Before 2020b, I used Target Scopes to trace & import the data, then removed the Target Scope after every iteration to clear the buffer. Target Scopes were removed in R2020b.
 
To accomplish the same workflow in R2020b and beyond, I am trying to use instruments to start/stop streaming signals to Simulation Data Inspector (SDI) during a running simulation. However, all the data will be shown in the same run in SDI. This makes it hard to visualize the data in SDI, and I cannot clear the data from SDI between the iterations.
 
How can I achieve my desired workflow in Simulink Real-Time R2020b and beyond?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Mar 2025
Edited: MathWorks Support Team on 21 Mar 2025

For MATLAB R2022a and later

Starting in R2022a, the Start/Stop Recording API is available to create a new SDI run while a real-time simulation is running. You could create multiple runs for each of your experiments, then delete older runs to discard the data (all while the same real-time simulation is running).  For more information, see the functions startRecording and stopRecording.
From R2022b, the same functionality is available through 'Start Recording' and 'Stop Recording' buttons in Simulink Toolstrip, SLRT Explorer, and MATLAB Apps:
For more information about the file logging and streaming workflows, see Signal Logging and Streaming Basics.

For MATLAB R2021b and earlier

As a workaround for R2020b through R2021b, it is possible to clear the data from SDI while running a real-time simulation by disconnecting the target using tg.disconnect. A new run will be created every time you disconnect and connect again with tg.connect. The code would look like this:
>> tg = slrealtime % repeat loop >> inst = slrealtime.Instrument >> inst.addSignal('mysignal') >> tg.addInstrument(inst) % start streaming >> tg.removeInstrument(inst) % stop streaming >> tg.removeAllInstruments >> tg.disconnect; % export data from SDI and clear >> Simulink.sdi.clear >> tg.connect % repeat loop

More Answers (0)

Community Treasure Hunt

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

Start Hunting!