%% Apply a Tolerance to a Signal in Multiple Runs
% You can use the Simulation Data Inspector programmatic interface to modify a parameter for the same signal in multiple runs. This example adds an absolute tolerance of 0.1 to a signal in all four runs of data.
% First, clear the workspace and load the Simulation Data Inspector session with the data. The session includes logged data from four simulations of a Simulink® model of a longitudinal controller for an aircraft.

Simulink.sdi.clear
Simulink.sdi.load('AircraftExample.mldatx');

%
% Use the Simulink.sdi.getRunCount function to get the number of runs in the Simulation Data Inspector. You can use this number as the index for a for loop that operates on each run.

count = Simulink.sdi.getRunCount;

%
% Then, use a for loop to assign the absolute tolerance of 0.1 to the first signal in each run.

for a = 1:count
    runID = Simulink.sdi.getRunIDByIndex(a);
    aircraftRun = Simulink.sdi.getRun(runID);
    sig = getSignalByIndex(aircraftRun,1);
    sig.AbsTol = 0.1;
end

% Copyright 2020 The MathWorks, Inc.