MATLAB: How to set default signal logging properties in Simulink Data Inspector

sdisimulink

When selecting a signal in Simulink Data Inspector, there are a number of properties that can be edited (shown in the bottom left-hand corner). How do I set defaults for these properties that apply to every simulation run? For example, I may want my signal to always use "zoh" as the setting for "Interp Method".

Best Answer

Some signal logging properties can be set to a default value from the Simulink model canvas. This is done by right-clicking the signal logging icon shown above the logged signal line (resembling the WiFi symbol), and selecting "Properties". Any properties set in this dialog box will apply to all simulation runs.
For properties that cannot be set to a default value from the model canvas, you can change the setting programmatically at the end of each simulation. The code below demonstrates how this can be done. It changes the setting of all logged signals from the latest simulation run to use "zoh" as the "Interp Method". You can place this code in the model's "StopFcn", so that it automatically executes at the end of every simulation. To edit the "StopFcn" callback, go to File > Model Properties > Model Properties > Callbacks.
% Get run IDs for most recent run
allIDs = Simulink.sdi.getAllRunIDs;
runID = allIDs(end);
% Get Run object
run = Simulink.sdi.getRun(runID);
% Change property for all signals in the latest run
for i = 1:run.SignalCount
% Get signal IDs
sigID = run.getSignalIDByIndex(i);
if (run.isValidSignalID(sigID))
% Get signal
sig = Simulink.sdi.getSignal(sigID);
% Change signal interpolation method
sig.InterpMethod = 'zoh';
end
end
To learn more about using Simulink Data Inspector programmatically, you may refer to the following documentation page: