MATLAB: Several draws from multivariate normal distribution

matricesmatrixmatrix arraymatrix manipulation

Let
MU=[1 2; 3 4; 5 6]
SIGMA=[2 0; 0 2]
I want to write one or two lines of code to draw R=10 unobservables from Normal((MU(1,:),SIGMA), Normal((MU(2,:),SIGMA), Normal((MU(3,:),SIGMA) without looping and store the results in a matrix 3x(R*2).

Best Answer

Cris,
Since your sigma matrix is diagonal, there is no need to use a multivariate distribution - your variables are completely independent - so what you are asking for is the same as selecting 10 samples each from 6 independent single variable normal distributions.
If this is truly the case, you can then create 3x20 matrices of mu and sigma and call normrnd like this:
mu = [repmat([1;3;5],[1,10]) repmat([2;4;6],[1,10])];
sigma = 2*ones(3,20);
normrnd(mu,sigma,3,20);
This will give you your 3x20 matrix, but will only work with diagonal co-variance matrices sigma.