clc
clear all
noR= xlsread('assignment_data.xlsx','B1:P1') % this imports excel data from the excel document required from
noD= xlsread('assignment_data.xlsx','B2:P2') % also this does too but this gets the other group.
[rN,cN]=size(noR) % these set the peramiters for my matrix perameters
LB=noR(1) % this sets another boundary 
span=3 % this shows my range for my boundaries.
HB=LB+span % this is the first boundary for my loop
daycount=0 
k=1;
for i=1:cN  % this allows me to control how many times I want the loop to be carried out.
    if noR(i)<HB 
        daycount=noD(i)+daycount; % this lets matlab search through to find the data
    else
        GNOD(k)=daycount; % else allows matlab to search in other places if they are not found in the first search
        daycount=noD(i); 
        k=k+1;  
        HB=HB+span; % these are other places matlab looks for answers if are not found
    end
end % this confirms the end of the search / loop
GNOD(k) = daycount; % this allows the display at the end or it wont show without this code.
GNOD 

MCV=LB+span/2:span:HB-span/2
fprintf('MCV= ')
fprintf('%g ',MCV)
fprintf('\n') % this here shows the mid value of each specific group.

figure (1) % this will bring up the first chart.

histogram ('binedges',LB:span:HB,'BinCounts' , GNOD , 'Facecolor' , [0 0 1]); % this allows me to set my boundaries for my first graph that i am going to create and also allows me to choose what colour that i want.
hold on % this saves the line above so that it can generate in the same graph as the next lines.
plot (MCV, GNOD) % this plots my graph
xticks ([15:1.5:33])  % this sets my steps of numbers on the x axis
yticks([0:1:25]) % this sets my steps of numbers on the y axis
xlabel ('Number of request classes') % this gives my x axis a title
ylabel ('Number of days') % this gives my y axis a title
title ('Histogram and polygon distribution of data set') % this gives my graph a title
LOC=find(GNOD==max(GNOD))
Mode=MCV(LOC)
text(Mode,1, ['Modal value=',num2str(Mode)] , 'Color' , 'yellow' , 'FontSize' , 13 , 'FontWeight' , 'bold' , 'HorizontalAlignment' , 'center')
% the code above codes the modal value also my colour choice, font size and
% the weight of it and also where i want it to show on my graph.

FreqDenc=sum(noD) % this shows us the total number of entries then we can work out how often the entries are for each group

Frequ = GNOD/FreqDenc % this calculate the frquency of each group 

Cumulfreq= cumsum  (Frequ); % this works out the cumulative sum

Cumulfreq1= 0.00 +  [ 0 Cumulfreq]% this is the cumulative data and thats what it shows. 

Inv_cum = 1 - [ 0 Cumulfreq ]% this shows the inverse cumulative frequency. in the brakcets it shows to start from 0 but add the 1 before the brakcets.


figure (2) % this will bring up a second chart

plot ([15:3:33],Cumulfreq1,'LineStyle', ' - - ','Color',[0 0 1],'LineWidth',1.5,'Marker','o'), grid on % this plots the cumulfreq1 withe the choice of linestyle the color which is blue how thick i wnat the line and also the type of markers and grid on just shows the lines on the graph.

hold on % this allows me to add more figures to the graph so i can write more codes below and them still show in same graph
vq = interp1(Cumulfreq1,1)
hold on
plot ( [15:3:33],Inv_cum,'LineStyle', '-.', 'Color',[ 1 0 0],'LineWidth',1.5,'Marker','o'), % this plots the cumulfreq1 withe the choice of linestyle the color which is red [ 1 0 0 ] how thick i wnat the line and also the type of markers and grid on just shows the lines on the graph.

grid minor 
xticks(15:1:33)% this sets the range on the x axis
yticks(0.10:0.10:1)  % this sets the range on the y axis
xlabel('Xi') % this gives the x axis a title
ylabel('Frequencies') % this gives the y axis a label
title('Ogive Distribution Frequencies') % this gives firgure 2 a title



