%% Predict RUL Using Hash Similarity Model
% Load training data.

load('hashTrainTables.mat')

% The training data is a cell array of tables. Each table is a degradation feature profile for a component. Each profile consists of life time measurements in the "Time" variable and corresponding degradation feature measurements in the "Condition" variable.
%
% Create a hash similarity model that uses hours as a life time unit and the following values as hashed features:
% Mean
% Standard deviation
% Kurtosis
% Median

mdl = hashSimilarityModel('Method',@(x) [mean(x),std(x),kurtosis(x),median(x)],...
                          'LifeTimeUnit',"hours");

%
% Train the similarity model using the training data. Specify the names of the life time and data variables.

fit(mdl,hashTrainTables,"Time","Condition")

%
% Load testing data. The test data contains the degradation feature measurements for a test component up to the current life time.

load('hashTestData.mat')

%
% Predict the RUL of the test component using the trained similarity model.

estRUL = predictRUL(mdl,hashTestData)

% The estimated RUL for the component is around 176 hours.
% Copyright 2012 The MathWorks, Inc.