% This program was used to create the confusion matrix for each subject. To run this program, load the data file Data_(name of subject), 
% and then run this program. The lines 118-122 that are commented here write the file into an excel sheet. They are commented because this m file
% is called in some other programs to make this matrix and in that case there is no need to create the excel sheets.



tempN1=[N(1,:,1);N(1,:,2);N(1,:,5);N(1,:,7);N(1,:,9);N(1,:,10);N(1,:,13);N(1,:,14);N(1,:,15);N(1,:,17);N(1,:,19);N(1,:,21);N(1,:,25);N(1,:,30);N(1,:,35)];
tempN2=[N(2,:,1);N(2,:,2);N(2,:,5);N(2,:,7);N(2,:,9);N(2,:,10);N(2,:,13);N(2,:,14);N(2,:,15);N(2,:,17);N(2,:,19);N(2,:,21);N(2,:,25);N(2,:,30);N(2,:,35)];
tempp1=[p(1,:,1);p(1,:,2);p(1,:,5);p(1,:,7);p(1,:,9);p(1,:,10);p(1,:,13);p(1,:,14);p(1,:,15);p(1,:,17);p(1,:,19);p(1,:,21);p(1,:,25);p(1,:,30);p(1,:,35)];
tempp2=[p(2,:,1);p(2,:,2);p(2,:,5);p(2,:,7);p(2,:,9);p(2,:,10);p(2,:,13);p(2,:,14);p(2,:,15);p(2,:,17);p(2,:,19);p(2,:,21);p(2,:,25);p(2,:,30);p(2,:,35)];

tempN3=[N(1,:,3);N(1,:,4);N(1,:,6);N(1,:,8);N(1,:,11);N(1,:,12);N(1,:,16);N(1,:,18);N(1,:,20);N(1,:,22);N(1,:,23);N(1,:,24);N(1,:,26);N(1,:,27);N(1,:,28);N(1,:,29);N(1,:,31);N(1,:,32);N(1,:,33);N(1,:,34);N(1,:,36);N(1,:,37);N(1,:,38);N(1,:,39)];
tempN4=[N(2,:,3);N(2,:,4);N(2,:,6);N(2,:,8);N(2,:,11);N(2,:,12);N(2,:,16);N(2,:,18);N(2,:,20);N(2,:,22);N(2,:,23);N(2,:,24);N(2,:,26);N(2,:,27);N(2,:,28);N(2,:,29);N(2,:,31);N(2,:,32);N(2,:,33);N(2,:,34);N(2,:,36);N(2,:,37);N(2,:,38);N(2,:,39)];
tempp3=[p(1,:,3);p(1,:,4);p(1,:,6);p(1,:,8);p(1,:,11);p(1,:,12);p(1,:,16);p(1,:,18);p(1,:,20);p(1,:,22);p(1,:,23);p(1,:,24);p(1,:,26);p(1,:,27);p(1,:,28);p(1,:,29);p(1,:,31);p(1,:,32);p(1,:,33);p(1,:,34);p(1,:,36);p(1,:,37);p(1,:,38);p(1,:,39)];
tempp4=[p(2,:,3);p(2,:,4);p(2,:,6);p(2,:,8);p(2,:,11);p(2,:,12);p(2,:,16);p(2,:,18);p(2,:,20);p(2,:,22);p(2,:,23);p(2,:,24);p(2,:,26);p(2,:,27);p(2,:,28);p(2,:,29);p(2,:,31);p(2,:,32);p(2,:,33);p(2,:,34);p(2,:,36);p(2,:,37);p(2,:,38);p(2,:,39)];



tempN5=reshape(N(1,:,:)+ N(2,:,:),[39 39])';
tempp5=reshape(p(1,:,:)+ p(2,:,:),[39 39])';

temp11=tempp1./tempN1;
temp1=[temp11(:,1) temp11(:,2) temp11(:,5) temp11(:,7) temp11(:,9) temp11(:,10) temp11(:,13) temp11(:,14) temp11(:,15) temp11(:,17) temp11(:,19) temp11(:,21) temp11(:,25) temp11(:,30) temp11(:,35)];
temp12=tempp2./tempN2;
temp2=[temp12(:,1) temp12(:,2) temp12(:,5) temp12(:,7) temp12(:,9) temp12(:,10) temp12(:,13) temp12(:,14) temp12(:,15) temp12(:,17) temp12(:,19) temp12(:,21) temp12(:,25) temp12(:,30) temp12(:,35)];
temp13=tempp3./tempN3;
temp3=[temp13(:,3) temp13(:,4) temp13(:,6) temp13(:,8) temp13(:,11) temp13(:,12) temp13(:,16) temp13(:,18) temp13(:,20) temp13(:,22) temp13(:,23) temp13(:,24) temp13(:,26) temp13(:,27) temp13(:,28) temp13(:,29) temp13(:,31) temp13(:,32) temp13(:,33) temp13(:,34) temp13(:,36) temp13(:,37) temp13(:,38) temp13(:,39)];
temp14=tempp4./tempN4;
temp4=[temp14(:,3) temp14(:,4) temp14(:,6) temp14(:,8) temp14(:,11) temp14(:,12) temp14(:,16) temp14(:,18) temp14(:,20) temp14(:,22) temp14(:,23) temp14(:,24) temp14(:,26) temp14(:,27) temp14(:,28) temp14(:,29) temp14(:,31) temp14(:,32) temp14(:,33) temp14(:,34) temp14(:,36) temp14(:,37) temp14(:,38) temp14(:,39)];
temp5=tempp5./tempN5;



vow={'' '@' 'A' 'E' 'I' 'O' 'R' 'U' 'W' 'Y' 'a' 'c' 'e' 'i' 'o' 'u'};
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'};
ind1=[40,1,2,5,7,9,10,13,14,15,17,19,21,25,30,35];
ind2=[40,3,4,6,8,11,12,16,18,20,22,23,24,26,27,28,29,31,32,33,34,36,37,38,39];


prin1(1,:)=vow;
for i=2:16
    for j=1:16
        if j==1
            prin1(i,1)=vow(1,i);
        else
            if ~isnan(temp1(i-1,j-1))
            prin1(i,j)={[num2str(p(1,ind1(1,j),ind1(1,i))) '/' num2str(N(1,ind1(1,j),ind1(1,i))) '=' num2str(temp1(i-1,j-1))]};
            else prin1(i,j)={''};
            end
         
        end
    end
end

prin2(1,:)=vow;
for i=2:16
    for j=1:16
        if j==1
            prin2(i,1)=vow(1,i);
        else
            if ~isnan(temp2(i-1,j-1))
            prin2(i,j)={[num2str(p(2,ind1(1,j),ind1(1,i))) '/' num2str(N(2,ind1(1,j),ind1(1,i))) '=' num2str(temp2(i-1,j-1))]};
            else prin2(i,j)={''};
            end
         
        end
    end
end

prin3(1,:)=cons;
for i=2:25
    for j=1:25
        if j==1
            prin3(i,1)=cons(1,i);
        else
            if ~isnan(temp3(i-1,j-1))
            prin3(i,j)={[num2str(p(1,ind2(1,j),ind2(1,i))) '/' num2str(N(1,ind2(1,j),ind2(1,i))) '=' num2str(temp3(i-1,j-1))]};
            else prin3(i,j)={''};
            end
         
        end
    end
end

prin4(1,:)=cons;
for i=2:25
    for j=1:25
        if j==1
            prin4(i,1)=cons(1,i);
        else
            if ~isnan(temp4(i-1,j-1))
            prin4(i,j)={[num2str(p(2,ind2(1,j),ind2(1,i))) '/' num2str(N(2,ind2(1,j),ind2(1,i))) '=' num2str(temp4(i-1,j-1))]};
            else prin4(i,j)={''};
            end
         
        end
    end
end

sym={'' '@' 'A' 'C' 'D' 'E' 'G' 'I' 'J' 'O' 'R' 'S' 'T' 'U' 'W' 'Y' 'Z' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'k' 'l' 'm' 'n' 'o' 'p' 'r' 's' 't' 'u' 'v' 'w' 'y' 'z'};
prin5(1,:)=sym;
for i=2:40
    for j=1:40
        if j==1
            prin5(i,1)=sym(1,i);
        else
            if ~isnan(temp5(i-1,j-1))
            prin5(i,j)={[num2str(tempp5(i-1,j-1)) '/' num2str(tempN5(i-1,j-1)) '=' num2str(temp5(i-1,j-1))]};
            else prin5(i,j)={''};
            end
         
        end
    end
end




% xlswrite('C:\Users\Anjali\Documents\MATLAB\NewFolder1\Reading Group\RGT-SCO_results\Tony.xlsx',prin1,1,'A1:P16');
% xlswrite('C:\Users\Anjali\Documents\MATLAB\NewFolder1\Reading Group\RGT-SCO_results\Tony.xlsx',prin2,2,'A1:P16');
% xlswrite('C:\Users\Anjali\Documents\MATLAB\NewFolder1\Reading Group\RGT-SCO_results\Tony.xlsx',prin3,3,'A1:Y25');
% xlswrite('C:\Users\Anjali\Documents\MATLAB\NewFolder1\Reading Group\RGT-SCO_results\Tony.xlsx',prin4,4,'A1:Y25');
% xlswrite('C:\Users\Anjali\Documents\MATLAB\NewFolder1\Reading Group\RGT-SCO_results\Tony.xlsx',prin5,5,'A1:AN40');






