clc;
clear all;
close all;
filename = 'STC_MARKS.xlsx';

% % Read the data from a excel sheet
sheet = 1;
xlRange = 'A1:G106';
data = xlsread(filename,sheet,xlRange) ; %% each column contains the samples belonging to each year 
group{1} = data(2:102,1);
group{2} = data(2:105,2);
group{3} = data(2:106,3);
group{4} = data(2:105,4);
group{5} = data(2:101,5);
group{6} = data(2:106,6);
group{7} = data(2:52,7);

% % MEAN
for i=1:7
    M(i)=mean(group{i});
end

% % Variance
for i=1:7
    S(i)=var(group{i});
end

% % Pooled variance
for i=1:7
    for j=1:7
        sp(i,j)=sqrt(((S(i)*(length(group{i}-1)))+(S(j)*(length(group{j}-1))))/(length(group{i})+length(group{j})-2));
    end
end

% % Z test
for i=1:7
    for j=1:7
        ztest(i,j)=(M(i)-M(j))/(sp(i,j)*sqrt((1/length(group{i}))+(1/length(group{j}))));
    end
end

for i=1:7
    for j=1:7
        P=ztest(i,j);
        temp=normcdf(P);
        confidence_level(i,j)=1-(temp*2);
    end
end
CONFIDENCE_LEVEL=abs(confidence_level(1:6,1:6));

k=1;
for i=1:200:1200
    l=1;
    for j=1:200:1200
        image(i:i+199,j:j+199)=CONFIDENCE_LEVEL(k,l)*100;
        l=l+1;
    end
    k=k+1;
end
figure;imagesc(image);
set(gca, 'XAxisLocation', 'top')
%Define colormap
c1=[0 1 0]; %G
c2=[1 1 0]; %Y
c3=[1 0 0]; %R
n1=20;
n2=20;
cmap=[linspace(c1(1),c2(1),n1);linspace(c1(2),c2(2),n1);linspace(c1(3),c2(3),n1)];
cmap(:,end+1:end+n2)=[linspace(c2(1),c3(1),n2);linspace(c2(2),c3(2),n2);linspace(c2(3),c3(3),n2)];
colormap(cmap')

%Plot

colormap(cmap');
xticks([1 200 400 600 800 1000 1200])
xticklabels({'2011','2012','2013','2014','2015','2016'})
xticks([1 200 400 600 800 1000 1200])
yticklabels({'2011','2012','2013','2014','2015','2016'})


figure;
% % Plot
for i=3
    for j=1
x = -6:0.0001:6;
z = normpdf(x,0,1);
plot(x,z);
hold on
% % temp2=-2:0.1:2;
% % temp3=normpdf(temp2);
temp2=ztest(i,j):-ztest(i,j)/(abs(ztest(i,j))*1000):ztest(j,i);
temp3=normpdf(temp2);
h=stem(temp2,temp3);
set(h, 'Marker', 'none')
 hold on
 plot(1.0812,0,'g*','MarkerSize',10)
 plot(-1.0812,0,'g*','MarkerSize',10)
    end
end


figure;
% % Plot
for i=3
    for j=2
x = -6:0.0001:6;
z = normpdf(x,0,1);
plot(x,z);
hold on
% % temp2=-2:0.1:2;
% % temp3=normpdf(temp2);
temp2=ztest(i,j):-ztest(i,j)/(abs(ztest(i,j))*1000):ztest(j,i);
temp3=normpdf(temp2);
h=stem(temp2,temp3);
set(h, 'Marker', 'none')
 hold on
 plot(0.5650,0,'g*','MarkerSize',10)
 plot(-0.5650,0,'g*','MarkerSize',10)
    end
end

