## Copyright (C) 2010 JieZhang
## 
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## hist_grad

## Author: JieZhang <JieZhang@JIEZHANG-GMU>
## Created: 2010-11-15

function [grad,freq] = hist_grad ()

%read-in grade data of 2007 ASTR111-003 class
%column 1: student ID; column 2: student grade
a=dlmread('ASTR111_003_2007_grad.txt','',2,0);

%obtain the grade from the second column
grad=a(:,2);

%count the frequency distribution in groups or bins
%there are 132 students in total

%count the data in 10 bins
%bin 1: 0  <= grade < 10
%bin 2: 10 <= grade < 20
%bin 3: 20 <= grade < 30
%bin 10: 90 <= grade <=100 
freq=[0,0,0,0,0,0,0,0,0,0]; %initialize the frequency distribution
for i=[1:132]
	if ((grad(i) >= 0) && (grad(i) < 10)), freq(1)=freq(1)+1; end
	if ((grad(i) >= 10) && (grad(i) < 20)), freq(2)=freq(2)+1; end
	if ((grad(i) >= 20) && (grad(i) < 30)), freq(3)=freq(3)+1; end
	if ((grad(i) >= 30) && (grad(i) < 40)), freq(4)=freq(4)+1; end
	if ((grad(i) >= 40) && (grad(i) < 50)), freq(5)=freq(5)+1; end
	if ((grad(i) >= 50) && (grad(i) < 60)), freq(6)=freq(6)+1; end
	if ((grad(i) >= 60) && (grad(i) < 70)), freq(7)=freq(7)+1; end
	if ((grad(i) >= 70) && (grad(i) < 80)), freq(8)=freq(8)+1; end
	if ((grad(i) >= 80) && (grad(i) < 90)), freq(9)=freq(9)+1; end
 	if ((grad(i) >= 90) && (grad(i) <= 100)), freq(10)=freq(10)+1; end
endfor

freq

%make histogram plot
bin=[5:10:95]  %subinterval of 10 with starting point at 5 and ending point at 95
%bin value serves as the center point of each bar in the histogram plot

hist(grad,bin) 

xlabel('Score','Fontsize',20)
ylabel('Frequency','Fontsize',20)
title('Histogram of Scores of 2007 ASTR111-003 class','Fontsize',16)
axis([0 100])  %set the plot xrange between [0 100]
grid on

print -dpng 'hist_grade.png'

endfunction
