function xdirtbal(X, pf, m) % xdirtbal(X, pf, m) "dirtball statistics" for the random variable X. % Generates a plot of the sample mean being trapped between the standard % deviation of the associated probability function as the number of % samples increases. m is an optional parameter that specifies which % experiment in the matrix X to use; if it is not specified, all % experiments are used. if nargin==3 M=size(X); if m<=0 | m>M(1) error('invalid value for m') end X=X(m,:); else X=X(:)'; end if ispf(pf)==0 error('not a valid probability function') end means=zeros(size(X)); ubounds=zeros(size(X)); lbounds=zeros(size(X)); V=var(pf); u=mmean(pf); U=ones(size(X)).*u; means(1)=X(1); ubounds(1)=u+V; lbounds(1)=u-V; for i=2:length(X), means(i)=(means(i-1)*(i-1)+X(i))/i; ubounds(i)=u+V/sqrt(i); lbounds(i)=u-V/sqrt(i); end subplot(1,1,1); plot(ubounds); hold on plot(lbounds); plot(U, 'b'); plot(means, 'r'); hold off