function sigma=makeRandomSigma2d(minl,maxl,ratio) % sigma=makeRandomSigma2d(minl,maxl) % % Generates in sigma a 2x2 covariance matrix. The variances elong the % principal directions are drawn uniformly from [minl,maxl]. % % sigma=makeRandomSigma2d(minl,maxl,ratio) draws the first variance at % random, and then sets the second one to ration*first one. % random rotation in 2D - more precisely, a random angle theta=unifrnd(-pi/2,pi/2); R=[cos(theta) -sin(theta); sin(theta) cos(theta)]; % the first eigenvalue drawn within the specified bounds lambda(1)=unifrnd(minl,maxl); if (nargin >= 3) lambda(2)=lambda(1)*ratio; else lambda(2)=unifrnd(minl,maxl); end Lambda=diag(lambda); sigma=R*Lambda*R';