> Is it possible to generalize this to data sets with any mean, variance and > covariance?
I didn't see the original posting, but it sounds like you want to specify an exact mean and covariance. This is not the same as generating from a theoretical mean and covariance (which is what I believe most people ought to want to do most of the time), because the result is less random than it should be. But the question comes up from time to time. Here's an example:
% Desired mean and covariance Mu = [10 15.5 9.99]; Sigma = [5 -3 0;-3 4 1;0 4 10];
% Create too-perfect sample with zero mean and identity covariance x = randn(100,length(Mu)); z = zscore(x); % if you don't have Statistics Toolbox, subtract mean and divide by std c = chol(cov(z)); z = z/c; cov(z) mean(z)
% Apply desired mean and covariance z = z*chol(Sigma); z = bsxfun(@plus,Mu,z); cov(z) mean(z)