clear all;
close all;
clc;

datadir = 'data';
actionset = 'ActionSet1.txt'; % select the action set

% Get valid filenames
file = fopen(actionset, 'r');

filenames = cell(1,1);

i = 1;
while ~feof(file)
    filenames(i) = textscan(file, '%str\n');
    i = i + 1;
end
fclose(file);

data = cell(2,1);
labels = zeros(2,1);
testdata = cell(2,1);
testlabels = zeros(2,1);
di = 1; % counter for data
ti = 1;
len = size(filenames, 2);
trainingsubjects = [1 3 5 7 9]; % the standard setup

for i = 1:len
    if (~isempty(find(trainingsubjects == getSubject(char(filenames{i})), 1)))% first 5 subjects as training
        data{di} = load (fullfile(datadir, [char(filenames{i}), '_skeleton3D.txt']));
        labels(di) = getLabel(char(filenames{i}));
        di = di + 1;
    else
        testdata{ti} = load (fullfile(datadir, [char(filenames{i}), '_skeleton3D.txt']));
        testlabels(ti) = getLabel(char(filenames{i}));
        ti = ti + 1;
    end
end

save MSRAction3D_AS1 data labels testdata testlabels;

fprintf('%s data file created successfully.\n', actionset);
clear all;
close all;