% The program generates the ps file barplots.ps. I usually convert it to 
% pdf online. For each subject, four bar plots are generated, one each for
% consonants in initial position, consonants in final position, vowels in 
% initial position and vowels in final position. The rounded percentage 
% error is displayed above the bar and the number of presentations are
% displyed above that.


load('DataNSCM/mastconf.mat')
load('DataNSCM/mastconb.mat')
load('DataNSCM/mastvowf.mat')
load('DataNSCM/mastvowb.mat')
child={'Alina','Angela','Anton','Bob','Carly','Edward','Evan','Joanna','Latisha','Laura','Miguel','Norene','Shauna','Teddy','Tony'};
vow=['@' 'A' 'E' 'I' 'O' 'R' 'U' 'W' 'Y' 'a' 'c' 'e' 'i' 'o' 'u'];
cons=['C' 'D' 'G' 'H' 'J' 'S' 'T' 'Z' 'b' 'd' 'f' 'g' 'h' 'k' 'L' 'm' 'n' 'p' 'r' 's' 't' 'v' 'w' 'y' 'z'];

for g=1:length(child)


[Y1,I1]=sort(1-(mastconf(g,1:25)./mastconf(g,26:50)),2,'descend');
[Y2,I2]=sort(1-(mastconb(g,1:25)./mastconb(g,26:50)),2,'descend');
[Y3,I3]=sort(1-(mastvowf(g,1:15)./mastvowf(g,16:30)),2,'descend');
[Y4,I4]=sort(1-(mastvowb(g,1:15)./mastvowb(g,16:30)),2,'descend');

figure(1)
subplot(2,1,1)

bar(Y1)

colormap summer;
ylim([0 1.3])
ylabel('Error')
title([child{1,g} ' Consonant in Initial Position '])


for i=1:25
    Xlab(i,1)=cons(1,I1(1,i));
    text(i-0.3,Y1(1,i)+0.14,num2str(round(Y1(1,i)*100)));
    text(i-0.3,Y1(1,i)+0.24,num2str(mastconf(g,25+I1(1,i))));
end
set(gca,'XTick',1:25)
set(gca,'XTickLabel',Xlab)


subplot(2,1,2)

bar(Y2)
colormap summer;
ylim([0 1.3])
ylabel('Error')
title([child{1,g} ' Consonant in Final Position '])

for i=1:25
    Xlab(i,1)=cons(1,I2(1,i));
    text(i-0.3,Y2(1,i)+0.14,num2str(round(Y2(1,i)*100)));
    text(i-0.3,Y2(1,i)+0.24,num2str(mastconb(g,25+I2(1,i))))
end

set(gca,'XTick',1:25)
set(gca,'XTickLabel',Xlab)


    if g==1
    psname= 'barplots';
    print ( '-dpsc2', psname, '-f1' )
    else
    print ( '-dpsc2', psname, '-append', '-f1' ) 
    end
    close
    
figure(2)
subplot(2,1,1)

bar(Y3)
colormap summer;
ylim([0 1.3])
ylabel('Error')
title([child{1,g} ' Vowel in Initial Position'])

for i=1:15
    Xlab(i,1)=vow(1,I3(1,i));
    text(i-0.3,Y3(1,i)+0.14,num2str(round(Y3(1,i)*100)));
    text(i-0.3,Y3(1,i)+0.24,num2str(mastvowf(g,15+I3(1,i))))
end

set(gca,'XTick',1:15)
set(gca,'XTickLabel',Xlab)


subplot(2,1,2)

bar(Y4)
colormap summer;
ylim([0 1.3])
ylabel('Error')
title([child{1,g} ' Vowel in Final Position'])

for i=1:15
    Xlab(i,1)=vow(1,I4(1,i));
    text(i-0.3,Y4(1,i)+0.14,num2str(round(Y4(1,i)*100)));
    text(i-0.3,Y4(1,i)+0.24,num2str(mastvowb(g,15+I4(1,i))))
end

set(gca,'XTick',1:15)
set(gca,'XTickLabel',Xlab)

    
print ( '-dpsc2', psname, '-append', '-f2' )  
close

end
