MATLAB: Programmatic Control of turning on and off Simulation Data Logging

datadisableenableloggingsimulink

I have a number of signals where I am performing data logging. I want to be able to quit streaming ALL data signals temporarily for several runs, then reinstate streaming for subsequent runs, with a pair of “disableStreaming” and “enableStreaming” function calls.

Best Answer

In releases prior to R2016b, there is not direct way to do this. Attached is an example script which has been tested with the built-in VDP model. You can use this script as is, or use this script as a direction to create your own file. Some comments before using this script:
1. Make sure that the lines which you wish to be recorded (assuming data logging is done on signal lines), have 'Log signal data' checked (see 'Logging and accessibility' tab inside 'Signal Properties' context menu of that line).
2. If you want to visualize the data that is being logged, make sure the Simulation Data Inspector has the option 'Send Logged workspace data to Data Inspector' enabled. You can get more information on where to find this option at the following documentation page:
3. Please make sure that data logging is enabled for all the required signals before you run the script as the script captures all the line handles that are associated with data logging.
As mentioned above, we assume that data logging is performed on signal lines and hence the script is using the FIND_SYSTEM command to get the handles to all the lines. You can read more about the FIND_SYSTEM function at the following documentation link:
Since MATLAB R2016b, you can turn off data logging in a Simulink model with the following MATLAB command:
>> set_param(bdroot, 'InstrumentedSignals', [])
From the User Interface, you can select a group of signals (or use Ctrl+A to select all) and then use the option from the Simulation Data Inspector (SDI) toolbar menu to turn on/off all selected signals.
In R2017a, logging and streaming options were merged. So you can do the same thing using model explorer or model data view to batch select in the spreadsheet and check/uncheck the "Log data" box.