 clear
% addpath ./mat

tic;
% Initialize Some initial Constants
%%
%CONS = {'C','D','G','J','S','T','Z','b','d','f','g','h','k','L','m','n','p',...
%    'r','s','t','v','w','y','z'};
CONS = {'p','b','t','d','k','g','f','v','T','D','s','z','S','Z','h','C','J',...
    'm','n','G','w','y','r','L'};
conOrd = [17,8,20,9,13,11,10,21,6,2,19,24,5,7,12,1,4,15,16,3,22,23,18,14];
nCONS = length(CONS); %We use 24 constants
%VOWS = {'@','A','E','I','O','R','U','W','Y','a','c','e','i','o','u'};
VOWS = {'i','e','u','o','c','Y','W','O','R','@','A','a','I','E','U'};
vowOrd = [13,12,15,14,11,9,8,5,6,1,2,10,4,3,7];
nVOWS = length(VOWS); %We use 15 vowels

frictivesAffricates = { 'C', 'D', 'h', 'J', 'S', 'T', 'Z', 'f', 's', 'v', 'z'};
iFrictivesAffricates = [ismember(CONS,frictivesAffricates) zeros(1,nVOWS)];
stops = { 'b', 'd', 'g', 'k', 'p', 't' };
iStops = [ismember(CONS,stops)  zeros(1,nVOWS)];
nasalsLiquidsGlides = {'G', 'L', 'm', 'n', 'r', 'w', 'y'};
iNasalsLiquidsGlides = [ismember(CONS,nasalsLiquidsGlides)  zeros(1,nVOWS)];
vowels = VOWS;
iVowels = [zeros(1,nCONS)  ones(1,nVOWS)];
groups = {'frictivesAffricates','stops','nasalsLiquidsGlides','vowels'};

RD = {'Alina','Angela','Edward',...
    'Latisha','Laura','Norene',...
    'Shauna','Teddy','Tony'};
RC = {'Anton','Bob','Carly','Evan',...
    'Joanna','Miguel'};
SUBJECTS = {RD{:}, RC{:}};
nSUBJECTS = length(SUBJECTS);

%% Load in Data for Subjects to Generate Stacked Bar Graphs
for i = 1 : nSUBJECTS
    subject = SUBJECTS(i);
    eval(['load ' subject{:} '.mat'])
     singlet(CMs{1}, CONS, nCONS, conOrd, i, SUBJECTS{i}, 'CIC'); %Jie 08312015 code factorization
    singlet(CMs{2}, CONS, nCONS, conOrd, i, SUBJECTS{i}, 'CFC');
     singlet(CMs{3}, VOWS, nVOWS, vowOrd, i, SUBJECTS{i}, 'VIC');
     singlet(CMs{4}, VOWS, nVOWS, vowOrd, i, SUBJECTS{i}, 'VFC');
end

toc;

