%% Visualize Trendability of Lifetime Data in Ensemble Datastore
% Consider the lifetime data of 4 machines. Each machine has 4 fault codes for the potential condition indicators-voltage, current, and power. trendabilityEnsemble.zip is a collection of 4 files where every file contains a timetable of lifetime data for each machine - tbl1.mat, tbl2.mat, tbl3.mat and tbl4.mat. You can also use files containing data for multiple machines. For each timetable, the organization of the data is as follows:
%
% When you perform calculations on tall arrays, MATLAB® uses either a parallel pool (default if you have Parallel Computing Toolbox™) or the local MATLAB session. To run the example using the local MATLAB session, change the global execution environment by using the mapreducer function.

mapreducer(0)

% 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 trendabilityEnsemble.zip;
ens = fileEnsembleDatastore(pwd,'.mat');
ens.DataVariables = {'Voltage','Current','Power','FaultCode','Machine'};
% Make sure that the function for reading data is on path
addpath(fullfile(matlabroot,'examples','predmaint','main')) 
ens.ReadFcn = @readtable_data;
ens.SelectedVariables = {'Voltage','Current','Power','FaultCode','Machine'};

%
% Visualize the trendability of the potential prognostic features with 'Machine' as the member variable and group the lifetime data by 'FaultCode'. Grouping the lifetime data ensures that trendability calculates the metric for each fault code separately.

trendability(ens,'MemberVariable','Machine','GroupBy','FaultCode');

% trendability returns a histogram plot with the features ranked by their trendability values. A higher trendability value indicates a more suitable prognostic parameter. For instance, the candidate feature Current has the highest degree of trendability for machines with FaultCode 1.

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

% Copyright 2018 The MathWorks, Inc.
%