Description 
MVNRND2 Random vectors from the multivariate normal distribution.
R = MVNRND2(MU,SIGMA,NUM) returns a NUMbyD matrix R of multivariate normal random vectors whose mean and covariance matrix match the given input parameters, MU (1D vector) and SIGMA (DbyD matrix)
[...] = MVNRND2(...,COVNORM) determines normalization for covariance
0 : Normalizes by NUM1. This makes cov(R) the best unbiased estimate of the covariance matrix (Default)
1 : Normalizes by NUM and produces the second moment matrix of the observations about their mean.
MU : Either a 1byD row vector, or a scalar across dimensions.
SIGMA : Either a DbyD positive semidefinite matrix, or 1byD row vector of a diagonal matrix, or scalar representing that value along the diagonal.
NUM : Positive integer at least D+1 in value.
COVNORM : 0 or 1 (Any nonzero value will be taken as 1)
Note: This is different from the MVNRND function in the Statistics Toolbox, as that samples from a multivariate normal distribution with mean MU and covariance SIGMA. The sampled mean and covariance may be different from the given inputs. This functions finds a collection of multivariate normal random vectors whose mean and covariance match the given input parameters, MU and SIGMA.
Example 1:
Find 5 numbers from the univariate normal distribution that have mean 50 and sample variance of 2. Show output and test output to determine if answer is valid.
r=mvnrnd2(50,2,5), mean(r), cov(r)
Example 2:
Find 1000 bivariate normal random vectors with mean [1 2] and secondmoment matrix of [2 .3; .3 2]. Test output to determine if answer is valid.
r=mvnrnd2([1 2],[2 .3; .3 2],1000,1); mean(r), cov(r,1)
Example 3:
Find 1e6 multivariate normal random vectors of dimension 5 with mean [5 4 3 2 1], with variances [1 2 3 4 5] and that are uncorrelated. Test output to determine if answer is valid.
r=mvnrnd2([5 4 3 2 1],[1 2 3 4 5],1e6); mean(r), cov(r)
Example 4:
(This example requires the Statistics Toolbox)
MVNRND in the Statistics Toolbox samples from a multivariate distribution with the given input parameters. MVNRND2 finds a collection of multivariate normal random vectors whose mean and covariance match the given input parameters, MU and SIGMA. Show both results for the same input.
r=mvnrnd([0 3],[2 .3; .3 1],10); mean(r), cov(r)
r2=mvnrnd2([0 3],[2 .3; .3 1],10); mean(r2), cov(r2)
