%% Moving Window Calculation with Tall Array
% Use matlab.tall.movingWindow to calculate the moving median of airline arrival and departure delays.
%
% Create a datastore for the airlinesmall.csv data set and convert it into a tall array. The data contains information about arrival and departure times of US flights. Extract the ArrDelay and DepDelay variables, which are vectors of flight delays, to create a tall array containing the delays as separate columns.

varnames = {'ArrDelay', 'DepDelay'};
ds = tabularTextDatastore('airlinesmall.csv', 'TreatAsMissing', 'NA', ...
    'SelectedVariableNames', varnames);
tt = tall(ds);
tX = [tt.ArrDelay tt.DepDelay]

%
% Use matlab.tall.movingWindow to calculate the moving median of the data in the first dimension. Use a window size of 5,000.

fcn = @(x) median(x,1,'omitnan');
tA = matlab.tall.movingWindow(fcn,5000,tX)

% Gather the unique rows of the result into memory.

tA = gather(unique(tA,'rows'))

% Copyright 2018 The MathWorks, Inc.