% Program binorm2.m % % This MATLAB Code simulates a bivariate normal distribution % with read in means and standard deviations and the % correlation coefficient chosen at random between -1,1 xm=input('mean of the x variate: ') ym=input('mean of the y variate: ') xsig=input('standard deviation of the x variate: ') ysig=input('standard deviation of the y variate: ') s=1; while s>0; x=[ ]; y=[ ]; rho=2.*rand-1 i=0; while (i < 100), i=i+1; a=randn; x1=xm+xsig*a; y1=ym+rho*ysig*a+ysig*randn*sqrt(1-rho*rho); x=[x x1]; y=[y y1]; end; plot(x,y,'o'),pause rho; s=input('Do you want to stop - if so enter 0') end