% randvars2.m % Generates numerical histogram for Gaussian-distributed random numbers. clear Nrealiz=100000 histstart=-4; histend=4; histstep=0.2; tic r=randn(Nrealiz,1); binedges=histstart:histstep:histend; hist_unnorm=hist(r,binedges); pdf=hist_unnorm/(length(r)*histstep); figure plot(binedges,pdf,'b.'); hold on gaussian=1/sqrt(2*pi)*exp(-binedges.^2/2); plot(binedges,gaussian,'r-') toc