%% Compute Gear Condition Metrics from Ensemble Datastore
% Consider gearData.zip, a collection of 9 data sets where each file contains separate timetables for the TSA, difference, regular and residual signals.
% Extract the compressed files, read the data in the timetables, and create a fileEnsembleDatastore object using the timetable data. For more information on creating a file ensemble datastore, see fileEnsembleDatastore.

unzip gearData.zip;
ens = fileEnsembleDatastore(pwd,'.mat');
% Make sure that the function for reading data is on path
addpath(fullfile(matlabroot,'examples','predmaint','main')) 
ens.ReadFcn = @readData;
ens.DataVariables = {'TSA','Diff','Reg','Res'};
ens.SelectedVariables = ens.DataVariables;

%
% Compute the gear condition metrics using the data in the ensemble datastore.

[gearMetrics,info] = gearConditionMetrics(ens,'SignalVariable','TSA','DifferenceVariable','Diff','RegularVariable','Reg','ResidualVariable','Res')

% The output table contains 9 rows of metrics where each row corresponds to one data set.

rmpath(fullfile(matlabroot,'examples','predmaint','main')) % Reset path

% Copyright 2018 The MathWorks, Inc.