title: Creating a matrix of correlated vectors
body: <p>I'm trying to create 2 nxm matrices (A and B) where all columns of A and B are correlated to each other (0.6). The values in matrices A and B are drawn from separate normal distributions. I've got the following, but when I check the correlations in the output the're not 0.6. What am I doing wrong?</p>
  
  <pre><code>m=30
  n=100    
  %Two distributions
  Mu1=0.0033;
  stdev1=0.0208;
  Mu2=0.0033;
  stdev2=0.016801;
  cor=0.6;
  %creating a nxm matrix by calculating correlated vectors one by one
  for y=1:m
  W(1:n,1)=Mu1+stdev1*randn(n,1);
  W(1:n,2)=Mu2+stdev2*randn(n,1);
  R=[1 cor;cor 1];
  L=chol(R);
  W=W*L;
  %Transfer to seperate matrices A and B
  A(:,y)=W(:,1);
  B(:,y)=W(:,2);
  end 
  </code></pre>