% load data set: major.txt
major=load('major.txt');
size(major);
sum(major==1);
majorsize = [sum(major==1), sum(major==2), sum(major==3), sum(major==4), sum(major==5), sum(major==6)];
%draw bar graph (vertical)
bar(majorsize);
ylabel('Number of Students in Sta113');
majorname = {'BME', 'CE', 'ECE', 'EE', 'ME', 'NoMajor'};
set(gca, 'XtickLabel', majorname);


% draw relative frequency historgram
total = sum(majorsize)
bar(majorsize./total);

% copy function dotplot.m
data = normrnd(zeros(1, 50), ones(1, 50));
subplot(1,2,1);
dotplot(data);
subplot(1,2,2);
hist(data, 7);

% load oldfaith data
[date, duration, time]=textread('oldfaith.dat', '%d%f%d', 'headerlines',1);
help hist
% histogram
subplot(2,3,1);
hist(time, 5);
subplot(2,3,2);
hist(time, 10);
subplot(2,3,3);
hist(time, 15);
subplot(2,3,4);
hist(time, 20);
subplot(2,3,5);
hist(time, 25);
subplot(2,3,6);
hist(time, 30);

subplot(2,3,1);
dotplot(time);


% an example for unequal width histogram
data = [unifrnd(0,1,1,12),unifrnd(1,2,1,6), unifrnd(2,3, 1, 12), unifrnd(3, 4,1,24), 4.4, 4.8, 5.4, 5.8, 6.4, 6.8, 7.4, 7.8];
subplot(2,2,1);
dotplot(data);

subplot(2,2,2);
edg=[0 1 2 3 4 5 6 7 8];
[n, bin]=histc(data, edg);
rfreq = n./length(data);
bar(edg,rfreq, 'histc'); % draw histogram with classes defined by "edg"

subplot(2,2,3);
edg=[0 1 2 3 4 8];
[n, bin]=histc(data, edg);
rfreq = n/length(data);
bar(edg,rfreq, 'histc'); % draw histogram with classes defined by "edg"

subplot(2,2,4);
width =[edg(2:6)-edg(1:5),1];
bar(edg,rfreq./width , 'histc');