MATLAB: How to modify signal logging overrides for tests with multiple model references

loggingoverridereferencesignalsimulink test

I am running tests for a large model reference hierarchy, and I need to be able to selectively limit and control which signals are logged because otherwise I end up with data that I do not need.
When creating test cases using Simulink Test, I'm limiting the number of signals recorded by opening the Simulink 'Signal Logging Selector' and setting the Logging Mode to 'Override Signals'. I'm then able to use the GUI to select the signals I want to record for simulations.
I need to be able to individually select signals within the underlying reference models to record. Is there a way to save off the Simulink Signal Logging Selector 'Override Signals' configuration that is saved with my model and then just apply it when I go to batch run these test cases?

Best Answer

Firstly, the following page indicates that you should set "LoggingMode" to "OverrideSignals" to control the logging mode for the top level model and all referenced models.
It is also possible to use a mix of override signal logging settings and model-specified (ignore override) logging settings using an cell array for "LogAsSpecifiedByModels".
Secondly, the following example walks through how you can selectively modify the "ModelLoggingInfo" for specific models in a reference hierarchy, and "DataLogging" settings for specific signals within those models.
Pay particular attention to the "Log a Subset of Signals" example. It uses "findSignal" and a loop to change the "DataLoggingOverride" settings for each signal.
mi = Simulink.SimulationData.ModelLoggingInfo.createFromModel(...
'ex_bus_logging');
pos = mi.findSignal({'ex_bus_logging/CounterA' ...
'ex_mdlref_counter_bus/Bus Creator'}, 1)
for idx=1:length(mi.Signals)
mi.Signals(idx).LoggingInfo.DataLogging = (idx == pos);
end
To apply the override settings, you use the following syntax:
set_param(ex_bus_logging,'DataLoggingOverride', mi);
To save the "Override Signals" configuration to apply it later, use "get_param" as follows:
>>si = get_param(bdroot,'DataLoggingOverride')