%% Apply Reduction Functions to Tall Vector
% Create a tall table, extract a tall vector from the table, and then find the total number of elements in the vector.
%
% Create a tall table for the airlinesmall.csv data set. The data contains information about arrival and departure times of US flights. Extract the ArrDelay variable, which is a vector of arrival delays.

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

%
% Use matlab.tall.reduce to count the total number of non-NaN elements in the tall vector. The first function numel counts the number of elements in each block of data, and the second function sum adds together all of the counts for each block to produce a scalar result.

s = matlab.tall.reduce(@numel,@sum,tX)

%
% Gather the result into memory.

s = gather(s)

%
% Copyright 2018 The MathWorks, Inc.