clc
clear all
 
NoR=xlsread('Assignment_Data.xlsx','B1:P1') %Gives the first row of numbers from the excel document
NoD=xlsread('Assignment_Data.xlsx','B2:P2') %gives the second row from the excel document
 
[rN,cN]=size(NoR);
LB=NoR(1) %lower boundary
span=3 %width of the class
HB=LB+span; %This will indicate how I achieved the higher boundary 
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:span:HB-span/2]

figure (1)  
histogram('BinEdges',LB:span:HB,'BinCounts',GNOD,'FaceColor',[0 0 1]);
hold on
plot(MCV,GNOD,'color',[1 0 0],'LineWidth',(1.5));
xticks(15:1.5:33)%gives the start number, end number and difference in between numbers on the x axis 
yticks(0:1:25)%gives the start number, end number and difference in between numbers on the y axis 
xlabel('number of request classes')%This will display number of request classes on the x axis of the graph
ylabel('number of days')%This will display 'number of days' in the label on my y axis
title('histogram and polygon distribution of data set')%the title displayed above the graph
hold on
plot(MCV,GNOD,'Color',[1 0 0]),'Line Width',(1.5);%This is plotting the poloygon whilst indicating the width of the line
LOC=find(GNOD==max(GNOD))
mode=MCV(LOC)
text(mode,1, ['modal value',num2str(mode)] , 'Color' , 'yellow' , 'FontSize' , 13 , 'FontWeight' , 'bold' , 'HorizontalAlignment' , 'center')
%this will assign my text the colour yellow
%this will assign the bold weight to my text
%this will assign the font size 13 to my text
%this will give my text horizontal allignment in the centre of the graph
%Represents mode on my graph 
 
figure(2)
T= sum(NoD) %This specifies the period of time over which the data is taken
frequency= GNOD/T %This tells us that the frequncy is found be mutiplying GNOD by the time
Cumalativefrequency= cumsum(frequency)%This shows the cumulative frequency is achieved by using cumsum which adds together the frequencys 
Cumfrequency1= 0.00 + [ 0 Cumalativefrequency]
Inversecum = 1 - [ 0 Cumalativefrequency ]%including 0 value
plot ([15:3:33],Cumfrequency1,'LineStyle',' - - ','Color',[1 1 1],'LineWidth',1.5,'Marker','o'),
hold on
Y1=interp1(LB:span:HB,Cumfrequency1,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],Inversecum,'LineStyle','-.','Color',[ 1 1 1],'LineWidth',1.5,'Marker','o')%Inverse line on the graph
hold on
Y2=interp1(LB:span:HB,Inversecum,LB:0.1:HB,'pchip');
plot(LB:0.1:HB,Y2,'Linestyle','-.','Color',[1 0 0],'Linewidth',1.5)
grid minor%This ensures the grid lines are displayed smaller
xticks(15:1:33)%This will give the start and the end number on the x axis on the graph. it will give a count of 1 from 15 to 33
yticks(0.10:0.10:1)%This will give a number of 0 on the bottom of the y axis and a number of 1 at the top of the y axis. there will be a count of 0.1 from 0 to 1 on this axis 
xlabel('Xi')%This will update the x axis on the graph
ylabel('Frequencies')%This will update the y axis on the graph
title('Ogive Distribution Frequencies') %This will show what the title of the graph will be 

difference=abs(Y1-Y2);
Minimumdiff=min(difference);
ind=find(difference==min(difference));
xi=LB:0.1:HB;
median=xi(ind)
