clc
clear all
NoR=xlsread('Assignment_Data.xlsx','B1:P1')
NoD=xlsread('Assignment_Data.xlsx','B2:P2')
[rN,cN]=size(NoR)
LB=NoR(1);
span=3;
HB=LB+span; %how we achieve the higher boundary
daycount=0;
K=1;
for i=1:cN
    if NoR(i)<HB %if number of requests is lower than the highest boundary
        daycount=NoD(i)+daycount;
    else  %if the number of requests is not lower than ther highest boundary
        GNOD(K)=daycount;
        daycount=NoD(i);
        K=K+1;
        HB=HB+span;
    end
end
GNOD(K)=daycount;
GNOD
MCV=LB+span/2:span:HB-span/2
fprintf('MCV= ')
fprintf('%g ',MCV)
fprintf('\n')

histogram('BinEdges',LB:span:HB,'BinCounts',GNOD)
hold on
plot(MCV,GNOD,'color',[1 0 0])

LOC=find(GNOD==max(GNOD))
Mode=MCV(LOC)

text(25.5,2,'Modal Value=25.5','FontSize',13,'FontWeight','bold','HorizontalAlignment','center','color',[1 1 0])
 
figure(2)
%plots graph
Cum=(cumsum(GNOD)/sum(GNOD))
%cumlative data / total number of days 
y1=[0,Cum]; 
%ensures x values start at 0 
Inv=(cumsum(GNOD,'reverse')/sum(GNOD))
%calculates inverse cumlative divided by total number of days 
y2=[Inv,0];
%ensures 
X=[LB:span:HB];
%defines x values with step of 3 as span = 3 from lower to upper boundry 
plot(X,y1,'Marker','o','Color',[1 1 1],'MarkerEdgeColor',[0 0 1])
%displays cumlative frequency on graph with stated style and colour 
hold on 
%retains the information on graph so can add information for inverse
%cumlative frequency 
plot(X,y2,'Marker','o','Color',[1 1 1],'MarkerEdgeColor',[1 0 0])
%displays inverse cumlative frequency with stated style and colour 
xticks([15:1:33])
%shows labels on graph starting at 15 with step of 1 untill 33 
title('Ogive Distribution Frequencies')
%displays main heading
xlabel('xi')
%displays x axis 
ylabel('Frequencies')
%displays y axis 
grid on 
%displays lines at every whole number 
grid minor 
%displays more grid lines 
Y1=interp1(X,y1,15:0.1:33,'pchip');
%makes graph lines smoother by increasing the step between the numbers 
plot(15:0.1:33,Y1,'LineStyle','- -','Color',[0 0 1],'LineWidth',1.5)
%plots cumlative frequency graph with smoother lines 
Y2=interp1(X,y2,15:0.1:33,'pchip');
plot(15:0.1:33,Y2,'LineStyle','-.','Color',[1 0 0],'LineWidth',1.5)
%plots inverse cumlative frequency graph with smoother lines 
diff=abs(y1-y2);
%finds difference in cumlative and inverse cumlative frequency 
index=find(diff==min(diff));
%finds minimum value
Median=X(index) 
%finds medium 
Freq=GNOD/sum(NoD);%this will calculate frequency 
Num_MC=MCV .* GNOD; %Ni multiplied by Ci
format shortG %this will dictate the format 
Num_MCsquare= Num_MC .* MCV; %Ni.Ci squared
TABLE=table([{'Number of Requests xi'},{'[15,18['},{'[18,21['},{'[21,24['},{'[24,27['},{'[27,30['},{'[30,33]'};...

    {'Mid Class value Ci'},num2cell(MCV); ...

    {'Number of Days  Ni'},num2cell(GNOD); ...

    {'Frequency'},num2cell(Freq); ...

    {'Cumulative Frequency'},num2cell(Cum); ...

    {'Inverse Cumulated Frequency'},num2cell(Inv); ...

    {'Ni.Ci'},num2cell(Num_MC); ...

    {'Ni.Ci ^ 2'},num2cell(Num_MCsquare)]);
TABLE=splitvars(TABLE)

 %this creates table and imports information into excel

writetable(TABLE,'Assignment_Data.xlsx','Sheet',2)
Mean_MC=sum(Num_MC);

Mean=Mean_MC/sum(NoD)
%this calculates the mean 






