function histo(X, pf, n) % histo(X, pf, n) Plots a cumulative histogram of all samples and % experiments in the random variable matrix X against an associated % probability function specified by pf. pf may be a probability or % cumulative function. n is the number of bars in the histogram. n is % not needed for discrete probability function, and is optional for % continuous one. The default value for n is 10. X does not have to be % a matrix: it may be a vector. If pf is an empty matrix [], no function % will be plotted. % % The resulting plot represents a mass, density, or distribution % function. if nargin==2 n=10; end if ~(pf==[]) if iscf(pf)==0 & ispf(pf)==0 error('pf is not a valid function') end end rv=X(:)'; if pf==[] [N, x]=hist(rv, n); N=N./length(rv); elseif iscf(pf) cf=pf; if isdiscrt(cf)==0 [N, x]=hist(rv, n); else [N, x]=hist(rv, xvals(cf)); end N=N./length(rv); if isdiscrt(cf)==0 N=(N.*n)./(max(rv)-min(rv)); end CN=N; for i=2:length(N), CN(i)=CN(i)+CN(i-1); end N=CN; else if isdiscrt(pf)==0 [N, x]=hist(rv, n); else [N, x]=hist(rv, xvals(pf)); end N=N./length(rv); if isdiscrt(pf)==0 N=(N.*n)./(max(rv)-min(rv)); end end bar(x, N, 'r') hold on if ~(pf==[]) plotf(pf) end hold off