%% Edited by Jonathan Buie 
%  4/9/2014

% The purpose of this code is to expand on the previous work by Christoph
% we currently have plots for the Error vs entropy for the inital and final
% positions of the constonants and vowels. Now we would like to look at the
% individual tokens themselves!

% 9/16/2014
% We want to add additional graphs for individual speakers with all 36
% tokens of intrest

% 10/13/2014 We begin to look at statistical significance of the data, I
% believe we will start by looking at a Gaussian Mixture Model to group our
% data between the RC and RD groups and we need a statistical measure that
% can determine the cases of consonant confusions in which both RC & RD can
% or cant comprehend, and the cases with seperation.

% 11/4/2014 we can now generate all the cons and vows in initial and final
% position with quadratic regression lines. Further work needs to be done
% to find a statistical measure to determine a level of speration.

% 11/29/2014 We want to adjust the quadratic regression lines to be
% centered around 0 (i think).  So far I have adjust the lines to have
% scaling and centering parameters, mu, xhat = (x- xbar)/std

% 12/1/2014 Hopefully work with Statisticians for techniques for seperation
% metrics between data groups

% 12/14/2014 From our discussion in the group meeting we've discussed the
% use of Rank Order Error/Entropy graphs that would show another visual
% about the seperation of the two groups (RD & RC).  There are currently 8
% graphs for Error/Entropy Intial Positions, Error/Entropy Final Positions
% for each Consonants and Vowels. See (Rank Error Analysis)

% 2/5/2015 At this point in our research we want to focus on the consonants
% that are between 10% - 30% error.  We will make a spreadsheet subjects x
% confusions with the counts of errors for each that fall in these
% categories.

clear all
addpath ./mat
addpath ./bin

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'};
nCONS = length(CONS); %We use 24 constants
VOWS = {'@','A','E','I','O','R','U','W','Y','a','c','e','i','o','u'};
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);
%%
table = 0; % Create the initial and final output tables
if table
    output = cell(nCONS + nVOWS+2,nSUBJECTS*2+1); % add two rows and one column for titles
    % add target labels
    conIdx = 3:2+nCONS;
    output(conIdx,1) = CONS;
    vowIdx = 3+nCONS:size(output,1);
    output(vowIdx,1) = VOWS;
    output(1,2:2:end)=SUBJECTS;
    hIdx = 2:2:size(output,2);
    output(2,hIdx)=cellstr(repmat('H',nSUBJECTS,1));
    nIdx = 3:2:size(output,2);
    output(2,nIdx)=cellstr(repmat('N',nSUBJECTS,1));
    outFinal = output;
    outInitial = output;
    
    for i = 1 : nSUBJECTS
        subject = SUBJECTS(i);
        eval(['load ' subject{:} '.mat'])
        cm = CMs{1}; % CMs 1-2 Cons, 3-4 Vows (odd Initial, even Final),
        % Cons Initial
        N = sum(cm,2);  % Sum of the rows total of each occurance
        p = cm ./ repmat(N,1,size(cm,2) ); % horizontal stack column vects
        H = sum(log2(p.^(-p)),2);
        outInitial(conIdx,hIdx(i)) = num2cell(H);
        outInitial(conIdx,nIdx(i)) = num2cell(N);
        cm = CMs{2}; % CMs 1-2 Cons, 3-4 Vows (odd Initial, even Final),
        % Cons Final
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) );
        H = sum(log2(p.^(-p)),2);
        outFinal(conIdx,hIdx(i)) = num2cell(H);
        outFinal(conIdx,nIdx(i)) = num2cell(N);
        
        cm = CMs{3}; % CMs 1-2 Cons, 3-4 Vows (odd Initial, even Final),
        % Vows Initial
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) );
        H = sum(log2(p.^(-p)),2);
        outInitial(vowIdx,hIdx(i)) = num2cell(H);
        outInitial(vowIdx,nIdx(i)) = num2cell(N);
        cm = CMs{4}; % CMs 1-2 Cons, 3-4 Vows (odd Initial, even Final),
        % Vows Final
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) );
        H = sum(log2(p.^(-p)),2);
        outFinal(vowIdx,hIdx(i)) = num2cell(H);
        outFinal(vowIdx,nIdx(i)) = num2cell(N);
    end
    
    %% write csv file (only works with database toolbox)
    % outFinal = cell2dataset(outFinal);
    % export(outFinal,'file','final.csv','delimiter',',')
    %
    % outInitial = cell2dataset(outInitial);
    % export(outInitial,'file','initial.csv','delimiter',',')
    
    %% write csv file (works in every Matlab)
    fid = fopen('final.csv','w')
    numColumns = size(outFinal,2);
    % use repmat to construct repeating formats
    % ( numColumns-1 because no comma on last one)
    headerFmt = repmat('%s,',1,numColumns-1);
    numFmt = repmat('%f,',1,numColumns-2);
    numFmt = ['%s,' numFmt]; % add targets
    fprintf(fid,[headerFmt,'%s\n'],outFinal{1,:})
    fprintf(fid,[headerFmt,'%s\n'],outFinal{2,:})
    for i = 3 : size(outFinal,1)
        fprintf(fid,[numFmt,'%f\n'],outFinal{i,:})
    end
    fclose(fid)
    
    fid = fopen('initial.csv','w')
    numColumns = size(outInitial,2);
    % use repmat to construct repeating formats
    % ( numColumns-1 because no comma on last one)
    headerFmt = repmat('%s,',1,numColumns-1);
    numFmt = repmat('%f,',1,numColumns-2);
    numFmt = ['%s,' numFmt]; % add targets
    fprintf(fid,[headerFmt,'%s\n'],outInitial{1,:})
    fprintf(fid,[headerFmt,'%s\n'],outInitial{2,:})
    for i = 3 : size(outInitial,1)
        fprintf(fid,[numFmt,'%f\n'],outInitial{i,:})
    end
    fclose(fid)
end

christoph = 0; % generate Christophs old plots if == 1
if christoph
    %% plot H(P_e)
    set(0,'DefaultAxesFontSize',16)
    ci = 1; % consonant initial
    cf = 2; % consonant initial
    vi = 3; % vowel initial
    vf = 4; % vowel final
    rd = 1; % reading disabeled
    rc = 2; % reading control

    % prepare group CMs
    groupCM{rd,ci} = zeros(nCONS); groupCM{rc,ci} = zeros(nCONS);
    groupCM{rd,cf} = zeros(nCONS); groupCM{rc,cf} = zeros(nCONS);
    groupCM{rd,vi} = zeros(nVOWS); groupCM{rc,vi} = zeros(nVOWS);
    groupCM{rd,vf} = zeros(nVOWS); groupCM{rc,vf} = zeros(nVOWS);

    % create entropy and Pe matrix for RD group
    for i = 1 : nSUBJECTS
        subject = SUBJECTS(i);
        eval(['load ' subject{:} '.mat'])
        if i > length(RD)
            idxRDRC = rc;
        else
            idxRDRC = rd;
        end
        % groupCM 1st dimension RD or RC, second dimension 1-2 Cons, 3-4 Vows (odd Initial, even Final)
        groupCM{idxRDRC,ci} = groupCM{idxRDRC,ci} + CMs{ci}; % CMs 1-2 Cons, 3-4 Vows (odd Initial, even Final),
        groupCM{idxRDRC,cf} = groupCM{idxRDRC,cf} + CMs{cf};
        groupCM{idxRDRC,vi} = groupCM{idxRDRC,vi} + CMs{vi};
        groupCM{idxRDRC,vf} = groupCM{idxRDRC,vf} + CMs{vf};

    end

    % Initial targets, first dimension RD or RC, second dimension target
    entropy_initial = zeros(2, nCONS +nVOWS);
    error_initial = zeros(2, nCONS +nVOWS);
    entropy_final = zeros(2, nCONS +nVOWS);
    error_final = zeros(2, nCONS +nVOWS);

    % calculate H and Pe
    for idxRDRC = 1:2
        % consonants initial
        cm = groupCM{idxRDRC,ci};
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
        pc = diag(p);
        pe = ones(length(pc),1) - pc;
        H = sum(log2(p.^(-p)),2);
        entropy_initial(idxRDRC,1:nCONS) = H';
        error_initial(idxRDRC,1:nCONS) = pe';
        % vowels initial
        cm = groupCM{idxRDRC,vi};
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
        pc = diag(p);
        pe = ones(length(pc),1) - pc;
        H = sum(log2(p.^(-p)),2);
        entropy_initial(idxRDRC,nCONS+1:end) = H';
        error_initial(idxRDRC,nCONS+1:end) = pe';
        % consonants final
        cm = groupCM{idxRDRC,cf};
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
        pc = diag(p);
        pe = ones(length(pc),1) - pc;
        H = sum(log2(p.^(-p)),2);
        entropy_final(idxRDRC,1:nCONS) = H';
        error_final(idxRDRC,1:nCONS) = pe';
        % vowels final
        cm = groupCM{idxRDRC,vf};
        N = sum(cm,2);
        p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
        pc = diag(p);
        pe = ones(length(pc),1) - pc;
        H = sum(log2(p.^(-p)),2);
        entropy_final(idxRDRC,nCONS+1:end) = H';
        error_final(idxRDRC,nCONS+1:end) = pe';
    end

    %% Plot

    entropy_threshold = 1
    error_threshold = 0.25
    x=[1:100]/100;
    H1=log2((x).^(-x))+log2(((1-x)).^(-(1-x)));
    H2=log2((x).^(-x))+2*log2((((1-x)/2)).^(-(1-x)/2));
    H3=log2((x).^(-x))+3*log2((((1-x)/3)).^(-(1-x)/3));
    H4=log2((x).^(-x))+4*log2((((1-x)/4)).^(-(1-x)/4));
    % initial
    for group = 1:length(groups)
        iGroup = logical(eval(['i' ,regexprep(groups{group},'(\<[a-z])','${upper($1)}')]))
        figure
        plot(error_initial(rd,iGroup),entropy_initial(rd,iGroup),'xr');hold on;
        plot(error_initial(rc,iGroup),entropy_initial(rc,iGroup),'xb');
        l=legend('Reading Disabled','Reading Control')
        legend('boxoff')
        set(l,'Position',[0.5 0.15 0.035 0.05]);
        title(['H(p_e) for Targets (' groups{group} ') in Initial Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        % label data points
        labels = eval(groups{group});
        ixGroup= find(iGroup==1)
        for idx = find(entropy_initial(rd,iGroup) > entropy_threshold & error_initial(rd,iGroup) > error_threshold) 
            text(error_initial(rd,ixGroup(idx)) + 0.01, entropy_initial(rd,ixGroup(idx)) + 0.1 , labels{idx});
        end
        for idx = find(entropy_initial(rc,iGroup) > entropy_threshold & error_initial(rc,iGroup) > error_threshold)
            text(error_initial(rc,ixGroup(idx)) + 0.01, entropy_initial(rc,ixGroup(idx)) + 0.1, labels{idx});
        end

        fname = sprintf('HPeInitial%s.eps',regexprep(groups{group},'(\<[a-z])','${upper($1)}'));
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    end
    % final
    for group = 1:length(groups)
        iGroup = logical(eval(['i' regexprep(groups{group},'(\<[a-z])','${upper($1)}')]));

        figure
        plot(error_final(rd,iGroup),entropy_final(rd,iGroup),'xr');hold on;
        plot(error_final(rc,iGroup),entropy_final(rc,iGroup),'xb');
        l=legend('Reading Disabled','Reading Control')
        legend('boxoff')
        set(l,'Position',[0.5 0.15 0.035 0.05]);
        title(['H(p_e) for Targets (' groups{group} ') in Final Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        % label data points
        labels = eval(groups{group});
        ixGroup= find(iGroup==1)
        for idx = find(entropy_final(rd,iGroup) > entropy_threshold & error_final(rd,iGroup) > error_threshold)
            text(error_final(rd,ixGroup(idx)) + 0.01, entropy_final(rd,ixGroup(idx)) + 0.1 , labels{idx});
        end
        for idx = find(entropy_final(rc,iGroup) > entropy_threshold & error_final(rc,iGroup) > error_threshold)
            text(error_final(rc,ixGroup(idx)) + 0.01, entropy_final(rc,ixGroup(idx)) + 0.1, labels{idx});
        end
        fname = sprintf('HPeFinal%s.eps',regexprep(groups{group},'(\<[a-z])','${upper($1)}'));
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    end
end


%% Scatter Plots
%  When analyzing the data, the plots that intrest us the most appear to
%  have error above 20% with RD group 
tic;
letters = {'C','D','G','J','S','T','Z','b','d','f','g','h','k','L','m',...
    'n','p','r','s','t','v','w','y','z','@','A','E','I','O','R','U','W',...
    'Y','a','c','e','i','o','u'};
markers = {'o','+','*','x','s','d','^','v','>','<','p','h','.'};
iRc = {'Anton','Bob','Carly','Evan','Joanna','Miguel'};
iRD = {'Alina','Angela','Edward','Latisha','Laura','Norene',...
    'Shauna','Teddy','Tony'};
% iC = [ismember(letters,'C') zeros(1,nVOWS+nCONS)];
% iD = [ismember(letters,'D') zeros(1,nVOWS+nCONS)];
set(0,'defaultAxesFontSize',14)
ci = 1; % consonant initial
cf = 2; % consonant initial
vi = 3; % vowel initial
vf = 4; % vowel final
% will need to remove these and figure out how to get all 39 plots 8o
rc = 1;
rd = 2;

% prepare group CMs
subjectCM = cell(15,4);
for i = 1: nSUBJECTS
    subjectCM{i,ci} = zeros(nCONS); subjectCM{i,ci} = zeros(nCONS);
    subjectCM{i,cf} = zeros(nCONS); subjectCM{i,cf} = zeros(nCONS);
    subjectCM{i,vi} = zeros(nVOWS); subjectCM{i,vi} = zeros(nVOWS);
    subjectCM{i,vf} = zeros(nVOWS); subjectCM{i,vf} = zeros(nVOWS);
end

% create entropy and Pe matrix for RD group
for i = 1 : nSUBJECTS
    % The first 9 are the RD group last 6 are RC
    subject = SUBJECTS    eval(['load ' subject{:} '.mat'])

    subjectCM{i,ci} = subjectCM{i,ci} + CMs{ci}; 
    subjectCM{i,cf} = subjectCM{i,cf} + CMs{cf};
    subjectCM{i,vi} = subjectCM{i,vi} + CMs{vi};
    subjectCM{i,vf} = subjectCM{i,vf} + CMs{vf};
    
end

% initialize 
errorxsub_initial = zeros(nCONS + nVOWS,15);
errorxsub_initialc = zeros(nCONS + nVOWS,15);
errorxsub_final = zeros(nCONS + nVOWS,15);
errorxsub_finalc = zeros(nCONS + nVOWS,15);
entropyxsub_initial = zeros(nCONS + nVOWS,15);
entropyxsub_final = zeros(nCONS + nVOWS,15);

entropy_threshold = 1.1;
error_threshold = 0.25;

Ninit = zeros(39,15);
Nfin = zeros(39,15);
% calculate H and Pe
for subidx = 1:15
    % consonants initial
    cm = subjectCM{subidx,ci};
    N = sum(cm,2);
    Ninit(1:nCONS,subidx) = N; 
    p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
    pc = diag(p);
    cc = diag(cm);
    ce = N - cc;
    pe = ones(length(pc),1) - pc;
    H = sum(log2(p.^(-p)),2);
    entropyxsub_initial(1:nCONS,subidx) = H';
    errorxsub_initial(1:nCONS,subidx) = pe';
    errorxsub_initialc(1:nCONS,subidx) = ce';
    % vowels initial
    cm = subjectCM{subidx,vi};
    N = sum(cm,2);
    Ninit(nCONS+1:39,subidx) = N;
    p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
    pc = diag(p);
    cc = diag(cm);  % count correction
    ce = N - cc;    % count errors
    pe = ones(length(pc),1) - pc;
    H = sum(log2(p.^(-p)),2);
    entropyxsub_initial(nCONS+1:end,subidx) = H';
    errorxsub_initial(nCONS+1:end,subidx) = pe';
    errorxsub_initialc(nCONS+1:end,subidx) = ce';
    % consonants final
    cm = subjectCM{subidx,cf};
    N = sum(cm,2);
    Nfin(1:nCONS,subidx) = N; 
    p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
    pc = diag(p);
    cc = diag(cm);
    ce = N - cc;
    pe = ones(length(pc),1) - pc;
    H = sum(log2(p.^(-p)),2);
    entropyxsub_final(1:nCONS,subidx) = H';
    errorxsub_final(1:nCONS,subidx) = pe';
    errorxsub_finalc(1:nCONS,subidx) = ce';
    % vowels final
    cm = subjectCM{subidx,vf};
    N = sum(cm,2);
    Nfin(nCONS+1:end,subidx) = N;
    p = cm ./ repmat(N,1,size(cm,2) ); % normalize CM by number of trials
    pc = diag(p);
    cc = diag(cm);
    ce = N - cc;
    pe = ones(length(pc),1) - pc;
    H = sum(log2(p.^(-p)),2);
    entropyxsub_final(nCONS+1:end,subidx) = H';
    errorxsub_final(nCONS+1:end,subidx) = pe';
    errorxsub_finalc(nCONS+1:end,subidx) = ce';
%     ent_ind = find(entropyxsub_initial(:,subidx) < entropy_threshold ...
%         & errorxsub_initial(:,subidx) > error_threshold);
end
save(['data/error.mat'],'errorxsub_initial','errorxsub_final')
save(['data/entropy.mat'],'entropyxsub_initial','entropyxsub_final')
toc;
%% Plot
x=[1:100]/100;
H1=log2((x).^(-x))+log2(((1-x)).^(-(1-x)));
H2=log2((x).^(-x))+2*log2((((1-x)/2)).^(-(1-x)/2));
H3=log2((x).^(-x))+3*log2((((1-x)/3)).^(-(1-x)/3));
H4=log2((x).^(-x))+4*log2((((1-x)/4)).^(-(1-x)/4));
%% initial 
show_ini= 0;
if show_ini
    tic;
    for letter = 1:nCONS+nVOWS  % can change the number of letters to create fewer charts
    %for letter = 1:1
    %     iSub = logical(eval(['i' ,regexprep(letters{letter},'(\<[a-z])','${upper($1)}')]));
        figure
        for i = 1:15
            if letter == 3
                Ninit(letter,i) = 1; % to account for letter G
            end
            if i > length(RD)
                plot(errorxsub_initial(letter,i),entropyxsub_initial(letter,i),'xb',...
                    'Marker',markers{16-i},'MarkerSize',100/sqrt(Ninit(letter,i)));hold on;
            else
                plot(errorxsub_initial(letter,i),entropyxsub_initial(letter,i),'xr',...
                    'Marker',markers{i},'MarkerSize',100/sqrt(Ninit(letter,i)));hold on;
            end;
        end
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','EastOutside', 'FontSize',12);
        %legend('boxoff')
        %set(l,'Position',[0.5 0.15 0.035 0.05]);
        title(['H(p_e) for Letter (' letters{letter} ') in Initial Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        % label data points
        labels = SUBJECTS;
        ixSub = (1:15);
    %     for idx = find(entropyxsub_initial(letter,ixSub) < entropy_threshold & errorxsub_initial(letter,ixSub) > error_threshold) 
    % %         text(errorxsub_initial(letter,ixSub(idx)) + 0.075, entropyxsub_initial(letter,ixSub(idx))+0.02, labels{idx});
    %         text(errorxsub_initial(letter,ixSub(idx)) + 0.05, entropyxsub_initial(letter,ixSub(idx)) + 0.05,'HERE');
    %     end;

    %    fname = sprintf('HPeInitial%s.eps',regexprep(letters{letter},'(\<[a-z])','${upper($1)}'));
        if isstrprop(letters{letter},'lower')
            fname = sprintf('HPeInitial_%s.eps',letters{letter});
        else
            fname = sprintf('HPeInitial%s.eps',letters{letter});
        end
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    end
    toc;
end
%% Subjects with initial position
show_inixsub = 0;
if show_inixsub
    tic;
    for sub = 1:length(SUBJECTS)
        figure;
    % This section has constonants in initial position
        for i = 1: nCONS
            if i == 3
                Ninit(i,sub) = 1; % to account for the letter G
            end
            if i <= 13 % there are 13 symbols
                plot(errorxsub_initial(i,sub),entropyxsub_initial(i,sub),'xb',...
                    'Marker',markers{i},'MarkerSize',100/sqrt(Ninit(i,sub)));...
                    hold on;
            else
                plot(errorxsub_initial(i,sub),entropyxsub_initial(i,sub),'xr',...
                    'Marker',markers{i-13},'MarkerSize',100/sqrt(Ninit(i,sub)));...
                    hold on;      
            end
        end
        % We remove G because date removed for this point
        l=legend('C','D','J','S','T','Z','b','d','f','g','h','k','L','m',...
        'n','p','r','s','t','v','w','y','z');
        set(l,'Location','EastOutside', 'FontSize',8);

        title(['H(p_e) for ' SUBJECTS{sub} ' with Consonants Initial Position'])
        ylabel('H [bits]')
        xlabel('p_e')
    %    columnlegend(3, legend_str, 'Location','NorthWest','boxon') 
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        labels = CONS;

        ixTok = (1:(nCONS));
    %     for idx = find(entropyxsub_initial(ixTok,sub) < entropy_threshold & errorxsub_initial(ixTok,sub) > error_threshold) 
    % %         text(errorxsub_initial(letter,ixSub(idx)) + 0.075, entropyxsub_initial(letter,ixSub(idx))+0.02, labels{idx});
    %         text(errorxsub_initial(ixTok(idx),sub) + 0.05, entropyxsub_initial(ixTok(idx),sub) + 0.05,['ltr= ',letters{idx}]);
    %     end; 
        fname = sprintf('HPeInitialCONS_%s.eps',SUBJECTS{sub});
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    % this section has Vowels in initial Position  
        figure;
        for i = nCONS+1:nCONS + nVOWS

            if i <= nCONS +length(markers)% it is a constonant so make it green
                plot(errorxsub_initial(i,sub),entropyxsub_initial(i,sub),'xb',...
                    'Marker',markers{i-(nCONS)},'MarkerSize',100/sqrt(Ninit(i,sub)));...
                    hold on;
            else
                plot(errorxsub_initial(i,sub),entropyxsub_initial(i,sub),'xr',...
                    'Marker',markers{i-37},'MarkerSize',100/sqrt(Ninit(i,sub)));...
                    hold on;      
            end
        end
        l=legend('@','A','E','I','O','R','U','W','Y','a','c','e','i','o','u');
        set(l,'Location','EastOutside', 'FontSize',8);
        title(['H(p_e) for ' SUBJECTS{sub} ' with Vowels in Initial Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        labels = VOWS;

        ixTok = (nCONS+1:nCONS+nVOWS);
    %     for idx = find(entropyxsub_initial(ixTok,sub) < entropy_threshold & errorxsub_initial(ixTok,sub) > error_threshold) 
    % %         text(errorxsub_initial(letter,ixSub(idx)) + 0.075, entropyxsub_initial(letter,ixSub(idx))+0.02, labels{idx});
    %         text(errorxsub_initial(ixTok(idx),sub) + 0.05, entropyxsub_initial(ixTok(idx),sub) + 0.05,['ltr= ',letters{idx}]);
    %     end; 
        fname = sprintf('HPeInitialVOWS_%s.eps',SUBJECTS{sub});
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    end
    toc;
end

%% final
show_fin = 0;
if show_fin
    tic;
    for letter = 1:nCONS+nVOWS
    %for letter = 1:1
    %     iSub = logical(eval(['i' ,regexprep(letters{letter},'(\<[a-z])','${upper($1)}')]));
        figure
        for i = 1:15
            if letter == 12 || letter == 22 || letter == 23
                Nfin(letter,i) = 1;
            end
            if i >= length(RD)
                plot(errorxsub_final(letter,i),entropyxsub_final(letter,i),'xb',...
                    'Marker',markers{16-i},'MarkerSize',100/sqrt(Nfin(letter,i)));hold on;
            else
                plot(errorxsub_final(letter,i),entropyxsub_final(letter,i),'xr',...
                    'Marker',markers{i},'MarkerSize',100/sqrt(Nfin(letter,i)));hold on;
            end;
        end
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','EastOutside', 'FontSize',12);
        %legend('boxoff')
        %set(l,'Position',[0.5 0.15 0.035 0.05]);
        title(['H(p_e) for Letter (' letters{letter} ') in Final Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        % label data points
        labels = SUBJECTS;
        ixSub = (1:15);
    %     for idx = find(entropyxsub_final(letter,ixSub) < entropy_threshold & errorxsub_final(letter,ixSub) > error_threshold) 
    % %       text(errorxsub_final(letter,ixSub(idx)) + 0.05, entropyxsub_final(letter,ixSub(idx)) + 0.05, labels{idx});
    %         text(errorxsub_final(letter,ixSub(idx)) + 0.05, entropyxsub_final(letter,ixSub(idx)) + 0.05,'HERE');
    %     end;
    %    fname = sprintf('HPeFinal%s.eps',regexprep(letters{letter},'(\<[a-z])','${upper($1)}'));
        if isstrprop(letters{letter}, 'lower')
            fname = sprintf('HPeFinal_%s.eps',letters{letter});
        else    
            fname = sprintf('HPeFinal%s.eps',letters{letter});
        end
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    end
    toc;
end
%% Subjects with final position
show_finxsub = 0;
if show_finxsub
    tic;
    for sub = 1:length(SUBJECTS)
        figure;
    % This section has constonants in final position
        for i = 1: nCONS
            if i == 12 || i == 22 || i == 23
                Nfin(i,sub) = 1;
            end
            if i <= 13 % there are 13 symbols
                plot(errorxsub_final(i,sub),entropyxsub_final(i,sub),'xb',...
                    'Marker',markers{i},'MarkerSize',100/sqrt(Nfin(i,sub)));...
                    hold on;
            else
                plot(errorxsub_final(i,sub),entropyxsub_final(i,sub),'xr',...
                    'Marker',markers{i-13},'MarkerSize',100/sqrt(Nfin(i,sub)));...
                    hold on;      
            end
        end
        % Removed 'h', 'w','y' from the consonants final
        l=legend('C','D','G','J','S','T','Z','b','d','f','g','k','L','m',...
        'n','p','r','s','t','v','z');
        set(l,'Location','EastOutside', 'FontSize',8);
        title(['H(p_e) for ' SUBJECTS{sub} ' with Consonants Final Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        labels = CONS;

        ixTok = (1:(nCONS));
    %     for idx = find(entropyxsub_final(ixTok,sub) < entropy_threshold & errorxsub_final(ixTok,sub) > error_threshold) 
    % %         text(errorxsub_initial(letter,ixSub(idx)) + 0.075, entropyxsub_initial(letter,ixSub(idx))+0.02, labels{idx});
    %         text(errorxsub_final(ixTok(idx),sub) + 0.05, entropyxsub_final(ixTok(idx),sub) + 0.05,['ltr= ',letters{idx}]);
    %     end; 
        fname = sprintf('HPeFinalCONS_%s.eps',SUBJECTS{sub});
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    % this section has Vowels in initial Position  
        figure;
        for i = nCONS+1:nCONS + nVOWS

            if i <= nCONS +length(markers)% it is a constonant so make it blue
                plot(errorxsub_final(i,sub),entropyxsub_final(i,sub),'xb',...
                    'Marker',markers{i-(nCONS)},'MarkerSize',100/sqrt(Nfin(i,sub)));...
                    hold on;
            else
                plot(errorxsub_final(i,sub),entropyxsub_final(i,sub),'xr',...
                    'Marker',markers{i-37},'MarkerSize',100/sqrt(Nfin(i,sub)));...
                    hold on;      
            end
        end
        l=legend('@','A','E','I','O','R','U','W','Y','a','c','e','i','o','u');
        set(l,'Location','EastOutside', 'FontSize',8);
        title(['H(p_e) for ' SUBJECTS{sub} ' with Vowels in Final Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        % plot reference lines
        plot(x,H1,'LineStyle','-','Color',[0.6 0.6 0.6]);hold on;
        plot(1-x,H2,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H3,'LineStyle','-','Color',[0.6 0.6 0.6]);
        plot(1-x,H4,'LineStyle','-','Color',[0.6 0.6 0.6]);
        labels = CONS;

        ixTok = (nCONS+1:nCONS+nVOWS);
    %     for idx = find(entropyxsub_final(ixTok,sub) < entropy_threshold & errorxsub_final(ixTok,sub) > error_threshold) 
    % %         text(errorxsub_initial(letter,ixSub(idx)) + 0.075, entropyxsub_initial(letter,ixSub(idx))+0.02, labels{idx});
    %         text(errorxsub_final(ixTok(idx),sub) + 0.05, entropyxsub_final(ixTok(idx),sub) + 0.05,['ltr= ',letters{idx}]);
    %     end; 
        fname = sprintf('HPeFinalVOWS_%s.eps',SUBJECTS{sub});
        print(gcf, fullfile('./fig/', fname), '-depsc2');
    end
    toc;
end

% Here we can generate the graphs with the quadratic regressions 
%% initial w/ Regression 
show_iniReg= 0;
if show_iniReg
    tic;
    %for letter = 1:5;
    for letter = 1:nCONS+nVOWS  % can change the number of letters to create fewer charts
        figure
        for i = 1:15
            if letter == 3
                Ninit(letter,i) = 1; % to account for letter G
            end
            if i > length(RD)
                plot(errorxsub_initial(letter,i),entropyxsub_initial(letter,i),'xb',...
                    'Marker',markers{16-i},'MarkerSize',100/sqrt(Ninit(letter,i)));hold on;
            else
                plot(errorxsub_initial(letter,i),entropyxsub_initial(letter,i),'xr',...
                    'Marker',markers{i},'MarkerSize',100/sqrt(Ninit(letter,i)));hold on;
            end;
        end
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','EastOutside', 'FontSize',12);
        %legend('boxoff')
        %set(l,'Position',[0.5 0.15 0.035 0.05]);
        title(['H(p_e) for Letter (' letters{letter} ') in Initial Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        
        [pRD_ini(letter,1:3),~, muRD(letter,1:2)] = polyfit(errorxsub_initial(letter,1:length(RD)),...
        entropyxsub_initial(letter,1:length(RD)),2)
        x1 = 0:0.001:(max(errorxsub_initial(letter,1:length(RD)))+.1);
        y1 = polyval(pRD_ini(letter,1:3),x1,[],muRD(letter,:));
        hold on
        plot(x1,y1,'r')
        [pRC_ini(letter,1:3), ~, muRC(letter,1:2)] = polyfit(errorxsub_initial(letter,(length(RD)+1):end),...
            entropyxsub_initial(letter,(length(RD)+1):end),2)
        x2 = 0:0.001:(max(errorxsub_initial(letter,1:length(RD)))+.1);
        y2 = polyval(pRC_ini(letter,1:3),x2,[],muRC(letter,:));
        hold on
        plot(x2,y2,'b')
        if letter ~= 3
        axis([0,max(errorxsub_initial(letter,1:length(RD)))+.1, 0, ...
            2.5])%max(entropyxsub_initial(letter,1:length(RD)))+.25])
        end
        if isstrprop(letters{letter},'lower')
            fname = sprintf('HPeInitialREG_%s.eps',letters{letter});
        else
            fname = sprintf('HPeInitialREG%s.eps',letters{letter});
        end
        print(gcf, fullfile('./REGfigtemp/', fname), '-depsc2');
    end
    toc;
end

%% Final w/ Regression 
show_finReg= 0;
if show_finReg
    tic;
    for letter = 1:nCONS+nVOWS  % can change the number of letters to create fewer charts
       figure
        for i = 1:15
            if letter == 12 || letter == 22 || letter == 23
                Nfin(letter,i) = 1;
            end
            if i > length(RD)
                plot(errorxsub_final(letter,i),entropyxsub_final(letter,i),'xb',...
                    'Marker',markers{16-i},'MarkerSize',100/sqrt(Nfin(letter,i)));hold on;
            else
                plot(errorxsub_final(letter,i),entropyxsub_final(letter,i),'xr',...
                    'Marker',markers{i},'MarkerSize',100/sqrt(Nfin(letter,i)));hold on;
            end;
        end
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','EastOutside', 'FontSize',12);
        %legend('boxoff')
        %set(l,'Position',[0.5 0.15 0.035 0.05]);
        title(['H(p_e) for Letter (' letters{letter} ') in Final Position'])
        ylabel('H [bits]')
        xlabel('p_e')
        labels = SUBJECTS;
        ixSub = (1:15);
        
        pRD_fin(letter,1:3) = polyfit(errorxsub_final(letter,1:length(RD)),...
        entropyxsub_final(letter,1:length(RD)),2);
        x1 = 0:0.001:(max(errorxsub_final(letter,1:length(RD)))+.1);
        y1 = polyval(pRD_fin(letter,1:3),x1);
        hold on
        plot(x1,y1,'r')
        pRC_fin(letter,1:3) = polyfit(errorxsub_final(letter,(length(RD)+1):end),...
            entropyxsub_final(letter,(length(RD)+1):end),2);
        x2 = 0:0.001:(max(errorxsub_final(letter,1:length(RD)))+.1);
        y2 = polyval(pRC_fin(letter,1:3),x2);
        hold on
        plot(x2,y2,'b')
        if letter == 12 || letter == 22 || letter ==23
        else
            axis([0,max(errorxsub_final(letter,1:length(RD)))+.1, 0, ...
                2.5])%max(entropyxsub_final(letter,1:length(RD)))+.25])
        end
        if isstrprop(letters{letter},'lower')
            fname = sprintf('HPeFinalREG_%s.eps',letters{letter});
        else
            fname = sprintf('HPeFinalREG%s.eps',letters{letter});
        end
        print(gcf, fullfile('./REGfig/', fname), '-depsc2');
    end
    toc;
end

%% Rank Error Analysis
%  This is a great graphic to show seperation between the two groups need a
%  way to show this. This graphic will show number of low error consonats 
rank_err_ent = 1;

conArray = repmat(CONS',1,length(CONS));
vowArray = repmat(VOWS',1,length(VOWS));

% Error Inital Consonants
[sortErrorIntCon, idxEIC] = sort(errorxsub_initial(1:24,:),1);
conArrayEIC = conArray(idxEIC);
avgRDEIC = mean(sortErrorIntCon(1:24,1:length(RD)),2);
stdRDEIC = std(sortErrorIntCon(1:24,1:length(RD)),0,2);
avgRCEIC = mean(sortErrorIntCon(1:24,(length(RD)+1):end),2);
stdRCEIC = std(sortErrorIntCon(1:24,(length(RD)+1):end),0,2);

% Error Final Consonants
[sortErrorFinCon, idxEFC] = sort(errorxsub_final(1:24,:),1);
conArrayEFC = conArray(idxEFC);
avgRDEFC = mean(sortErrorFinCon(1:24,1:length(RD)),2);
stdRDEFC = std(sortErrorFinCon(1:24,1:length(RD)),0,2);
avgRCEFC = mean(sortErrorFinCon(1:24,(length(RD)+1):end),2);
stdRCEFC = std(sortErrorFinCon(1:24,(length(RD)+1):end),0,2);

% Entropy Initial Consonants
[sortEntropyIntCon, idxHIC] = sort(entropyxsub_initial(1:24,:),1);
conArrayHIC = conArray(idxHIC);
avgRDHIC = mean(sortEntropyIntCon(1:24,1:length(RD)),2);
stdRDHIC = std(sortEntropyIntCon(1:24,1:length(RD)),0,2);
avgRCHIC = mean(sortEntropyIntCon(1:24,(length(RD)+1):end),2);
stdRCHIC = std(sortEntropyIntCon(1:24,(length(RD)+1):end),0,2);

% Entropy Final Consonants
[sortEntropyFinCon, idxHFC] = sort(entropyxsub_final(1:24,:),1);
conArrayHFC = conArray(idxHFC);
avgRDHFC = mean(sortEntropyFinCon(1:24,1:length(RD)),2);
stdRDHFC = std(sortEntropyFinCon(1:24,1:length(RD)),0,2);
avgRCHFC = mean(sortEntropyFinCon(1:24,(length(RD)+1):end),2);
stdRCHFC = std(sortEntropyFinCon(1:24,(length(RD)+1):end),0,2);

[sortErrorIntVow, idxEIV] = sort(errorxsub_initial(25:end,:),1);
[sortErrorFinVow, idxEFV] = sort(errorxsub_final(25:end,:),1);
[sortEntropyIntVow,idxHIV] = sort(entropyxsub_initial(25:end,:),1);
[sortEntropyFinVow, idxHFV] = sort(entropyxsub_final(25:end,:),1);
if rank_err_ent
    y = 1:length(CONS);
    conRank = 0;
    if conRank
        
        
        % Error Initial Cons
        figure;
        
%       This is for the y axis as a log axis  RD
        
        semilogy(y,avgRCEIC,'b-',y,avgRDEIC,'r-','LineWidth',3);
        hold on
        
        h = errorbar(y,avgRCEIC,stdRCEIC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDEIC,stdRDEIC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0.01 1]);
        grid on
        semilogy(y,sortErrorIntCon(1:24,1:round(length(RD)/2)),'--',...
            y,sortErrorIntCon(1:24,(round(length(RD)/2)+1):length(RD)),...
            ':','LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Initial Consonants [RD subjects]'])
        ylabel('Percent Error')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IErrorConRD_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');
        
        % This is for the x axis as the log axis  RD
        figure;
        semilogx(avgRCEIC,y,'b-',avgRDEIC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCEIC,y,stdRCEIC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDEIC,y,stdRDEIC,[],{'r','r',2});
        hold on
        semilogx(sortErrorIntCon(1:24,1:round(length(RD)/2)),y,'--',...
            sortErrorIntCon(1:24,(round(length(RD)/2)+1):length(RD)),y,...
            ':','LineWidth',1)
        xlim([0.01 1])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Initial Consonants [RD subjects]'])
        xlabel('Percent Error')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IErrorConRD_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');       
        
        % For reading Controled group
        figure;
        semilogy(y,avgRCEIC,'b-',y,avgRDEIC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCEIC,stdRCEIC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDEIC,stdRDEIC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0.01 1]);
        grid on
        semilogy(y,sortErrorIntCon(1:24,(length(RD)+1):end),'--',...
            'LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Initial Consonants [RC Subjects]'])
        ylabel('Percent Error')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IErrorConRC_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');        
        
        figure;
        semilogx(avgRCEIC,y,'b-',avgRDEIC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCEIC,y,stdRCEIC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDEIC,y,stdRDEIC,[],{'r','r',2});
        hold on
        semilogx(sortErrorIntCon(1:24,(length(RD)+1):end),y,'--',...
            sortErrorIntCon(1:24,(length(RD)+1):end),y,...
            ':','LineWidth',1)
        xlim([0.01 1])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Initial Consonants [RC subjects]'])
        xlabel('Percent Error')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IErrorConRC_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');       

        figure; % Error Final Cons
        % for RD group
        % This is for the y axis as a log axis  RD
        semilogy(y,avgRCEFC,'b-',y,avgRDEFC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCEFC,stdRCEFC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDEFC,stdRDEFC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0.01 1]);
        grid on
        semilogy(y,sortErrorFinCon(1:24,1:round(length(RD)/2)),'--',...
            y,sortErrorFinCon(1:24,(round(length(RD)/2)+1):length(RD)),...
            ':','LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Final Consonants [RD subjects]'])
        ylabel('Percent Error')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FErrorConRD_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');
        
        % This is for the x axis as the log axis  RD
        figure;
        semilogx(avgRCEFC,y,'b-',avgRDEFC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCEFC,y,stdRCEFC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDEFC,y,stdRDEFC,[],{'r','r',2});
        hold on
        semilogx(sortErrorFinCon(1:24,1:round(length(RD)/2)),y,'--',...
            sortErrorFinCon(1:24,(round(length(RD)/2)+1):length(RD)),y,...
            ':','LineWidth',1)
        xlim([0.01 1])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Final Consonants [RD subjects]'])
        xlabel('Percent Error')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FErrorConRD_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');       
        
        % For reading Controled group
        figure;
        semilogy(y,avgRCEFC,'b-',y,avgRDEFC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCEFC,stdRCEFC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDEFC,stdRDEFC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0.01 1]);
        grid on
        semilogy(y,sortErrorFinCon(1:24,(length(RD)+1):end),'--',...
            'LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Final Consonants [RC Subjects]'])
        ylabel('Percent Error')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FErrorConRC_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');        
        
        figure;
        semilogx(avgRCEFC,y,'b-',avgRDEFC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCEFC,y,stdRCEFC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDEFC,y,stdRDEFC,[],{'r','r',2});
        hold on
        semilogx(sortErrorFinCon(1:24,(length(RD)+1):end),y,'--',...
            sortErrorFinCon(1:24,(length(RD)+1):end),y,...
            ':','LineWidth',1)
        xlim([0.01 1])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Final Consonants [RC subjects]'])
        xlabel('Percent Error')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FErrorConRC_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');

% Entropy Initial Cons
        figure;
        % This is for the y axis as a log axis  RD
        semilogy(y,avgRCHIC,'b-',y,avgRDHIC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCHIC,stdRCHIC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDHIC,stdRDHIC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0 3]);
        grid on
        semilogy(y,sortEntropyIntCon(1:24,1:round(length(RD)/2)),'--',...
            y,sortEntropyIntCon(1:24,(round(length(RD)/2)+1):length(RD)),...
            ':','LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Initial Consonants [RD subjects]'])
        ylabel('H [bits]')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IEntropyConRD_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');
        
        % This is for the x axis as the log axis  RD
        figure;
        semilogx(avgRCHIC,y,'b-',avgRDHIC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCHIC,y,stdRCHIC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDHIC,y,stdRDHIC,[],{'r','r',2});
        hold on
        semilogx(sortEntropyIntCon(1:24,1:round(length(RD)/2)),y,'--',...
            sortEntropyIntCon(1:24,(round(length(RD)/2)+1):length(RD)),y,...
            ':','LineWidth',1)
        xlim([0 3])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Initial Consonants [RD subjects]'])
        xlabel('H [bits]')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IEntropyConRD_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');       
        
        % For reading Controled group
        figure;
        semilogy(y,avgRCHIC,'b-',y,avgRDHIC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCHIC,stdRCHIC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDHIC,stdRDHIC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0 3]);
        grid on
        semilogy(y,sortEntropyIntCon(1:24,(length(RD)+1):end),'--',...
            'LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Initial Consonants [RC Subjects]'])
        ylabel('H [bits]')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IEntropyConRC_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');        
        
        figure;
        semilogx(avgRCHIC,y,'b-',avgRDHIC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCHIC,y,stdRCHIC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDHIC,y,stdRDHIC,[],{'r','r',2});
        hold on
        semilogx(sortEntropyIntCon(1:24,(length(RD)+1):end),y,'--',...
            sortEntropyIntCon(1:24,(length(RD)+1):end),y,...
            ':','LineWidth',1)
        xlim([0 3])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Initial Consonants [RC subjects]'])
        xlabel('H [bits]')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('IEntropyConRC_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');       

        figure; % Entropy Final Cons
        % for RD group
        % This is for the y axis as a log axis  RD
        semilogy(y,avgRCHFC,'b-',y,avgRDHFC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCHFC,stdRCHFC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDHFC,stdRDHFC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0 3]);
        grid on
        semilogy(y,sortEntropyFinCon(1:24,1:round(length(RD)/2)),'--',...
            y,sortEntropyFinCon(1:24,(round(length(RD)/2)+1):length(RD)),...
            ':','LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Final Consonants [RD subjects]'])
        ylabel('H [bits]')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FEntropyConRD_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');
        
        % This is for the x axis as the log axis  RD
        figure;
        semilogx(avgRCHFC,y,'b-',avgRDHFC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCHFC,y,stdRCHFC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDHFC,y,stdRDHFC,[],{'r','r',2});
        hold on
        semilogx(sortEntropyFinCon(1:24,1:round(length(RD)/2)),y,'--',...
            sortEntropyFinCon(1:24,(round(length(RD)/2)+1):length(RD)),y,...
            ':','LineWidth',1)
        xlim([0 3])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Alina','Angela','Edward',...
            'Latisha','Laura','Norene','Shauna','Teddy','Tony');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Final Consonants [RD subjects]'])
        xlabel('H [bits]')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FEntropyConRD_logx');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');       
        
        % For reading Controled group
        figure;
        semilogy(y,avgRCHFC,'b-',y,avgRDHFC,'r-','LineWidth',3);
        hold on
        h = errorbar(y,avgRCHFC,stdRCHFC,'b','LineWidth',2);
        set(get(h,'Parent'),'YScale','log');
        g = errorbar(y,avgRDHFC,stdRDHFC,'r','LineWidth',2);
        set(get(g,'Parent'),'YScale','log');
        ylim([0 3]);
        grid on
        semilogy(y,sortEntropyFinCon(1:24,(length(RD)+1):end),'--',...
            'LineWidth',1)
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Final Consonants [RC Subjects]'])
        ylabel('H [bits]')
        xlabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FEntropyConRC_logy');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');        
        
        figure;
        semilogx(avgRCHFC,y,'b-',avgRDHFC,y,'r-','LineWidth',3);
        hold on
        h = errorbarxy(avgRCHFC,y,stdRCHFC,[],{'b','b',2});
        hold on
        g = errorbarxy(avgRDHFC,y,stdRDHFC,[],{'r','r',2});
        hold on
        semilogx(sortEntropyFinCon(1:24,(length(RD)+1):end),y,'--',...
            sortEntropyFinCon(1:24,(length(RD)+1):end),y,...
            ':','LineWidth',1)
        xlim([0 3])
        grid on
        l=legend('RC','RD','stdRC','stdRD','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Final Consonants [RC subjects]'])
        xlabel('H [bits]')
        ylabel('Rank Order of Consonants')
        hold off
        fname = sprintf('FEntropyConRC_logx');
        print(gcf, fullfile('./RankFigs_noAvg/', fname), '-depsc2');

    end
    %% Here we can do the Vowels our focus is on the consonants however it's
    % important to at least visualize this data for any additional that may
    % help paint a clearer picture
    vowRank = 0;
    if vowRank   
        x = 0:(length(VOWS)-1);
        
        figure; % Error Initial Vows
        plot(x, sortErrorIntVow(1:end,1:length(RD)),'-', x, ...
            sortErrorIntVow(1:end,(length(RD)+1):end),'--','LineWidth',2)
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Vowels in Initial Position'])
        ylabel('Percent Error')
        xlabel('Rank Order of Vowels')
        fname = sprintf('RankErrInitVow');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');

        figure; % Error Final Vows
        plot(x, sortErrorFinVow(1:end,1:length(RD)),'-', x, ...
            sortErrorFinVow(1:end,(length(RD)+1):end),'--','LineWidth',2)
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Vowels in Final Position'])
        ylabel('Percent Error')
        xlabel('Rank Order of Vowels')
        fname = sprintf('RankErrFinalVow');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2'); 

        figure; % Entropy Initial Vows
        plot(x, sortEntropyIntVow(1:end,1:length(RD)),'-', x, ...
            sortEntropyIntVow(1:end,(length(RD)+1):end),'--','LineWidth',2)
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Vowels in Initial Position'])
        ylabel('Entropy [bits]')
        xlabel('Rank Order of Vowels')
        fname = sprintf('RankEntropyInitVow');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');

        figure; % Entropy Final Cons
        plot(x, sortEntropyFinVow(1:end,1:length(RD)),'-', x, ...
            sortEntropyFinVow(1:end,(length(RD)+1):end),'--','LineWidth',2)
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel');
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Vowels in Final Position'])
        ylabel('Entropy [bits]')
        xlabel('Rank Order of Vowel')
        fname = sprintf('RankEntropyFinalVow');
        print(gcf, fullfile('./RankFigs2/', fname), '-depsc2');
    end
%% Rank Ordered Consonants for ALL Subject (No AVGS)    
    allRank = 1;
    if allRank
        % Cons Initial Err
        semilogy(y,sortErrorIntCon(1:24,1:length(RD)),'-',...
            y,sortErrorIntCon(1:24,length(RD)+1:end),...
            '--','LineWidth',1.5);
        ylim([0.01 1]);
        grid on
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel'); 
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Consonants Initial Position'])
        ylabel('Percent Error')
        xlabel('Rank Ordered Consonants') 
        
        fname = sprintf('IErrorCon_logy');
        print(gcf, fullfile('./RankFig_noAvg/', fname), '-depsc2');         
        
        % Cons Final Err
        figure;
        semilogy(y,sortErrorFinCon(1:24,1:length(RD)),'-',...
            y,sortErrorFinCon(1:24,length(RD)+1:end),...
            '--','LineWidth',1.5);
        ylim([0.01 1]);
        grid on
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel'); 
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Error For Consonants Final Position'])
        ylabel('Percent Error')
        xlabel('Rank Ordered Consonants')
        
        fname = sprintf('FErrorCon_logy');
        print(gcf, fullfile('./RankFig_noAvg/', fname), '-depsc2');
        
        % Cons Initial H
        figure;
        semilogy(y,sortEntropyIntCon(1:24,1:length(RD)),'-',...
            y,sortEntropyIntCon(1:24,length(RD)+1:end),...
            '--','LineWidth',1.5);
        ylim([0 3]);
        grid on
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel'); 
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Consonants Initial Position'])
        ylabel('H [bits]')
        xlabel('Rank Ordered Consonants') 
        
        fname = sprintf('IEntropyCon_logy');
        print(gcf, fullfile('./RankFig_noAvg/', fname), '-depsc2');
        
        % Cons Final H
        figure;
        semilogy(y,sortEntropyFinCon(1:24,1:length(RD)),'-',...
            y,sortEntropyFinCon(1:24,length(RD)+1:end),...
            '--','LineWidth',1.5);
        ylim([0 3]);
        grid on
        l=legend('Alina','Angela','Edward','Latisha','Laura','Norene',...
            'Shauna','Teddy','Tony','Anton','Bob','Carly','Evan',...
            'Joanna','Miguel'); 
        set(l,'Location','NorthEastOutside', 'FontSize',12);
        title(['Rank Entropy For Consonants Final Position'])
        ylabel('H [bits]')
        xlabel('Rank Ordered Consonants') 
        
        fname = sprintf('FEntropyCon_logy');
        print(gcf, fullfile('./RankFig_noAvg/', fname), '-depsc2');
    end
end

 
hists = 0;
if hists
    errHistFin = cell((nCONS*4),nSUBJECTS);
    errHistInit = cell((nCONS*4),nSUBJECTS);
    row = 1;
    
    % % This first section is for the Consonats in Initial Position for
    % Error in rank order.  Count the number of occurances with the hopes
    % there may be some sort of similarities.
    
    for i = 1:(nCONS)
%         errHist{row,1} = 'Rank'; errHist(row,2) = num2cell(i);
        errHistFin{row,1} = sprintf('Rank %d',i);
        errHistFin{row,2} = sprintf('%d unique responses',...
            length(unique(conArrayEIC(i,1:15))));
        row = row + 1;
        [errHistFin(row,1:length(unique(conArrayEIC(i,1:15)))),a,b] = ...
            unique(conArrayEIC(i,1:15));
        row = row + 1;
        errHistFin(row,1:length(unique(conArrayEIC(i,1:15)))) = ...
            num2cell(hist(b,1:length(errHistFin(row,1:length(unique(conArrayEIC(i,1:15)))))));
        row = row + 1;
        errHistFin{row,1} = [];
        row = row+1;
    end
    
    row = 1;
    for i = 1:(nCONS)
%         errHist{row,1} = 'Rank'; errHist(row,2) = num2cell(i);
        errHistInit{row,1} = sprintf('Rank %d',i);
        errHistInit{row,2} = sprintf('%d unique responses',...
            length(unique(conArrayEFC(i,1:15))));
        row = row + 1;
        [errHistInit(row,1:length(unique(conArrayEFC(i,1:15)))),a,b] = ...
            unique(conArrayEFC(i,1:15));
        row = row + 1;
        errHistInit(row,1:length(unique(conArrayEFC(i,1:15)))) = ...
            num2cell(hist(b,1:length(errHistInit(row,1:length(unique(conArrayEFC(i,1:15)))))));
        row = row + 1;
        errHistInit{row,1} = [];
        row = row+1;
    end
end
%% Count Matrices for consonants between 10% - 30% error
% use the conArray matrix
% We will be using the sorted conArray & sorted Error/Entropy Con matrices
sortCaEIC = conArray(idxEIC);
sortCaEFC = conArray(idxEFC);
sortCaEIV = vowArray(idxEIV);
sortCaEFV = vowArray(idxEFV);

% for i = 1:length(SUBJECTS)
%     indx = find(sortErrorIntCon(:,i) > 0.0999 & sortErrorIntCon(:,i) < 0.31);
%     indx2 = find(sortErrorFinCon(:,i) > 0.0999 & sortErrorFinCon(:,i) < 0.31);
%     tmpA(1:length(indx),i) = sortCaEIC(indx,i);
%     tmpB(1:length(indx2),i) = sortCaEFC(indx2,i);
% end

tempMat = zeros(length(SUBJECTS),length(CONS)+length(VOWS));
tempMatp = zeros(length(SUBJECTS), length(CONS)+length(VOWS));

for i = 1:length(SUBJECTS)
    for j = 1:length(sortCaEIC)
        k = find(strcmp(CONS,sortCaEIC{j,i}));
        tempMat(i,k) = errorxsub_initialc(k,i);
        tempMatp(i,k) = errorxsub_initial(k,i);
    end
    for j = 1:length(sortCaEIV)
        k = find(strcmp(VOWS,sortCaEIV{j,i}))+length(CONS);
        tempMat(i,k) = errorxsub_initialc(k,i);
        tempMatp(i,k) = errorxsub_initial(k,i);
    end
end

tempMatpc = tempMatp.*100;
% Consonants ratio of num incorrect and % error
for i=1:length(SUBJECTS)
    for j = 1:length(CONS)
        ratioMat{i,j} = [sprintf('%2.2f',tempMat(i,j)) '/' num2str(Ninit(j,i)')];
        perMat{i,j} = [sprintf('%2.2f',tempMatpc(i,j)) '(' num2str(Ninit(j,i)') ')'];
    end
end
% Now do vowels
for i=1:length(SUBJECTS)
    for j = length(CONS)+1:length(CONS)+length(VOWS)
        ratioMat{i,j} = [sprintf('%2.2f',tempMat(i,j)) '/' num2str(Ninit(j,i)')];
        perMat{i,j} = [sprintf('%2.2f',tempMatpc(i,j)) '(' num2str(Ninit(j,i)') ')'];
    end
end

perMat = regexprep(perMat,'^0.00\(\w*\)','');
ratioMat = regexprep(ratioMat,'^0.0.\/\w*','');

countMat_intp = [[CONS,VOWS];perMat];
countMat_intp = [[' ';SUBJECTS'],countMat_intp;;];

countMat_int = [[CONS,VOWS];ratioMat];
countMat_int = [[' ';SUBJECTS'],countMat_int];

clear tempMat; clear tempMatp
clear ratioMat; clear perMat;

for i = 1:length(SUBJECTS)
    for j = 1:length(sortCaEFC)
        k = find(strcmp(CONS,sortCaEFC{j,i}));
        tempMat(i,k) = errorxsub_finalc(k,i);
        tempMatp(i,k) = errorxsub_final(k,i);
    end
    for j = 1:length(sortCaEFV)
        k = find(strcmp(VOWS,sortCaEFV{j,i}))+length(CONS);
        tempMat(i,k) = errorxsub_finalc(k,i);
        tempMatp(i,k) = errorxsub_final(k,i);
    end    
end

tempMatpc = tempMatp.*100;

for i=1:length(SUBJECTS)
    for j = 1:length(CONS)+length(VOWS)
        ratioMat{i,j} = [sprintf('%2.2f',tempMat(i,j)) '/' num2str(Nfin(j,i)')];
        perMat{i,j} = [sprintf('%2.2f',tempMatpc(i,j)) '(' num2str(Nfin(j,i)') ')'];
    end
end
perMat = regexprep(perMat,'^0.00\(\w*\)','');
ratioMat = regexprep(ratioMat,'^0...\/\w*','');

countMat_finp = [[CONS,VOWS];perMat];
countMat_finp = [[' ';SUBJECTS'],countMat_finp];

countMat_fin = [[CONS,VOWS];ratioMat];
countMat_fin = [[' ';SUBJECTS'],countMat_fin];

