function ms = mvlognrnd(nvars, means, vars, corr) %mvlognrnd returns nvars LOGNORMAL with means, vars, and correlation % means is the means of your random variable if (length(means) == 1) means = means*ones(1,nvars); end % vars is the variances of your ransom variables if (length(vars) == 1) vars=vars*ones(1, nvars); end % corr is the correlation coeffient for your random variables; at this point corr must be the same for all means = zeros(1,nvars); temp0 = repmat(sqrt(vars),[nvars 1]) .* repmat(sqrt(vars)',[1 nvars]); temp1 = temp0 .* (corr*ones(nvars,nvars)); temp2 = temp0 .* ((1-corr)*eye(nvars,nvars)); varcovmatrix = (temp1+temp2); ms = mvnrnd(means, varcovmatrix,1); ms = exp(ms);