clc
clear all
NoR=xlsread('Assignment_Data.xlsx','B1:P1')%Gives values for the first row of the excel document which relates to the number of requests
NoD=xlsread('Assignment_Data.xlsx','B2:P2')%Gives values for the second row of the excel document which realtes to the number of days
[rN,cN]=size(NoR);
LB=NoR(1)%Lower Boundary = number of requests in location 1
Span=3;%Span of data groups
HB=LB+Span;%Higher boundary = lower bandary + span of class
daycount=0;
k=1;
for i=1:cN
    if NoR(i)<HB
        daycount=NoD(i)+daycount;
    else
        GNOD(k)=daycount;
        daycount=NoD(i);
        k=k+1;
        HB=HB+Span;
    end
end
GNOD(k)=daycount

MCV=[LB+Span/2:3:HB-Span/2]%mid class value is the lower boundary plus half the span of the class of data

figure(1)
histogram('BinCount',GNOD,'BinEdges',15:3:33,'FaceColor',[0 0 1]);

xticks([15:1.5:33])
yticks([0:1:25])
xlabel('Number of request classes')%inserting X axis label
ylabel('Number of Days')%inserting Y axis label
title('Histogram and Polygon distribution of data set')%Inserting title for the graph
hold on
plot(MCV,GNOD,'Color',[1 0 0],'LineWidth',(1.5));%Plotting the polygon and specifying the line width
L=find(GNOD==max(GNOD))
Mode=MCV(L)%determine mode
text(25.5,2,'Modal Value=25.5','FontSize',13,'FontWeight','bold','HorizontalAlignment','center','color',[1 1 0])%inserting text and text characteristics 


figure(2)
FD=sum(NoD)
Frequ=GNOD/FD%calculating frequency
Cum_frequ= cumsum(Frequ)%cumulative frequency 
Cum_frequ1= 0.00 + [ 0 Cum_frequ]%including 0 value
Inv_cum= 1 - [ 0 Cum_frequ ]%inverse cumulative frequency inluding 0 value
plot ([15:3:33],Cum_frequ1,'Color',[1 1 1],'MarkerEdgeColor',[0 0 1],'Marker','o'),%plotting the cumulative line on the graph
hold on 
Y1=interp1(LB:Span:HB,Cum_frequ1,LB:0.1:HB,'pchip');
plot(LB:0.1:HB,Y1,'LineStyle','--','Color',[0 0 1],'LineWidth',1.5)
grid on
hold on
plot ( [15:3:33],Inv_cum,'Color',[ 1 1 1],'MarkerEdgeColor',[1 0 0],'Marker','o')%plotting the inverse cumulative line on the graph
hold on 
Y2=interp1(LB:Span:HB,Inv_cum,LB:0.1:HB,'pchip');
plot(LB:0.1:HB,Y2,'LineStyle','-.','Color',[1 0 0],'LineWidth',1.5) 
grid minor
xticks(15:1:33)%determining the spaces for the X ticks on the X axis
yticks(0.10:0.10:1)%determining the spaces for the Y ticks on the Y axis
xlabel('Xi')%label for X axis 
ylabel('Frequencies')%label for Y axis
title('Ogive Distribution Frequencies')%title of the ogive graph

%Calculating Median
Diff=abs(Y1-Y2);
MinDiff=min(Diff);
ind=find(Diff==min(Diff));
Xi=LB:0.1:HB;
Median=Xi(ind)

%Creating table for grouped data
ICF=cumsum(Cum_frequ,'reverse');
T=table({'Number of Requests xi';'Mid Class ci';'Number of Days ni';'Frequency';'Cumulated Frequency';'Inversely Cumulated Frequency';'ni.ci';'ni.ci^2'},[{'[15,18[','[18,21[','[21,24[','[24,27[','[27,30[','[30,33['};num2cell(MCV);num2cell(GNOD);num2cell(Frequ);num2cell(Cum_frequ);num2cell(ICF);num2cell(GNOD.*MCV);num2cell(GNOD.*MCV.^2)]);
writetable(T,'Assignment_Data.xlsx','Sheet',2);



