clc %  this clears the command window
clear all % This clears the the workspace

noR=xlsread('Assignment_Data','B1:P1');
noD=xlsread('Assignment_Data','B2:P2');% these incorporate the required data from the excell file
[rN,cN]=size(noR); % row number and collumn number 
LB=noR(1);% lower boundary
span=3; % range of boundary 
HB=LB+span; % highest boundary is the lower bounary plus the span required
daycount=0; % the day count is given the number 0 before the loop
k=1;
for i=1:cN % the for loop will continue to loop until the last collummn valuve 
    if noR(i)<HB
        daycount=noD(i)+daycount; % if the number achieved is lower than the upper boundary HB the daycount figure is added to nummber of days 'noD'
    else
        GNOD(k)=daycount; % grouped number of days 'GNOD is equal to daycount
        daycount=noD(i); 
        k=k+1;
        HB=HB+span;    end
end
GNOD(k)=daycount;
disp('GNOD -')
disp(GNOD) % the results are the displayed to the user

MCV=LB+span/2:span:HB-span/2; %This defines the vector MCV.  The Lower Boundary plus the span defines the starting point of the range.  The step is defined by the span and the end point of the range is defined by the Higher Boundary minus half of the span. 
fprintf('MCV= ') 
fprintf('%g',MCV) % removes zeroes
fprintf('/n') 

  
histogram('BinEdges',LB:span:HB,'BinCounts', GNOD , 'Facecolor' , [0 0 1]); %GNOD is a vector
hold on % keeps histrogram in place
plot(MCV,GNOD) % plots a ploygon with the MCV and GNOD displayed

xticks ([15:1.5:33]) % the requires steps needed on the x axis
yticks ([0:1:25]) % the required steps needed for the y axis

xlabel( 'Number of Request Classes' ) % the title of the x axis
ylabel('Number of Days') % the title of the y axis
title ('Histogram and Polygon distribution of data set') % title of the polygon

LOC=find(GNOD == max(GNOD));
Mode=MCV(LOC);
text( Mode,1, ['Modal value=' , num2str(Mode)] ,'Color' , 'yellow' , 'FontSize', 13 , 'FontWeight' , 'bold' , 'HorizontalAlignment' , 'center')
hold off

noD = sum(noD); % Total number of days in NoD 
frequency = GNOD/noD; % frequency calculation

cumulative_frequency = cumsum(frequency); % cumulative frequency 

actual_cumulative_frequency = 0.00 +  [ 0 cumulative_frequency];% the actual cumulative frequency  

inverse_cumulative = 1 - [ 0 cumulative_frequency ];% The inverse cumulative frequency calculated 


figure (2) 
plot ([15:3:33], actual_cumulative_frequency,'LineStyle', ' - - ','Color',[0 0 1],'LineWidth',1.5,'Marker','o'), grid on % This plots the Ogive Distribution plot in the required colour and line widths and marker style

hold on; % keeps the histrogram in place 
vq = interp1(actual_cumulative_frequency,1); % The 'vq' is incorportated to the actual cumulative frequency as a vector
hold on; % keeps the histrogram in place 
plot ( [15:3:33], inverse_cumulative ,'LineStyle', '-.', 'Color',[ 1 0 0],'LineWidth',1.5,'Marker','o'), 

grid minor; 
xticks(15:1:33);% X-Axis and the required ste[p 
yticks(0.10:0.10:1);  % Y-Axis the required step
xlabel('Xi'); % X-Axis Title
ylabel('Frequencies'); % Y-Axis Title
title('Ogive Distribution Frequencies'); % Title of the chart










