% % An extension of example 9.1 % This illustrates the 1-D histogram using relative frequency and frequency. % % Written by: % -- % John L. Weatherwax 2005-08-14 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- load galaxy % The 'hist' function can return the % bin centers and frequencies. % Use the default number of bins - 10. % % run now with nBins=5,50 % nBins = 5; nBins = 50; [n, x] = hist(EastWest,nBins); % Plot and use the argument of width = 1 % to get bars that touch. bar(x,n,1,'w'); title('Frequency Histogram - Galaxy Data') xlabel('Velocity') ylabel('Frequency') % Now create a relative frequency histogram. % Divide each box by the total number of points. bar (x,n/140,1,'w') title('Relative Frequency Histogram - Galaxy Data') xlabel('Velocity') ylabel('Relative Frequency')