function [X] = cov2data(SigmaX, n, dist) %cov2data Creates a data set from a covariance matrix. % % USE: % [data] = cov2data(covX, n, dist) % % INPUTS: % covX = the covariance matrix. % n = sample size. % dist = a string specifying the distribution from which data are crated. % See the help file on random. Default is Normal (or Gaussian). % % Output: % data = realizations of variables with the specified distribution. % % As of 2/18/2002, only normal distribution is supported. % Tomo Eguchi % 18 February 2002 if nargin >= 2, dist = 'norm'; end [nrS, ncS] = size(SigmaX); numVar = nrS; % spectral decomposition of SigmaX and order eigenvalues and eigenvectors: [U, lambda] = eigOrder(SigmaX); Y = zeros(n, numVar); % initialize the Y matrix % Y contains random variables with means 0 and variances = eigenvalues. for i = 1:numVar, Y(:, i) = random(dist, 0, sqrt(lambda(i,i)), n, 1); end % create X, i.e., observables according to the covariance matrix of X. X = Y * U';