How do I generate K samples of size n from a multivariate normal?

I'm given a multivariate normal distribution with
mu = [3,4,0.5]'
and covariance matrix [1,0.2,0.7;0.2,1,0.5;0.7,0.5,1].
I would like to generate 5000 samples of size 40 and store them.
I think I understand how to generate a sample of size forty,
mux = [3;4;0.5];
sigma = [1 0.2 0.7;0.2 1 0.5;0.7 0.5 1];
R = mvnrnd(mux,sigma,40);
But I don't know how to repeat the process 5000 times or store it. I suspect I should use a for loop but am unsure. Thanks for any help you can provide.

 Accepted Answer

mux = [3;4;0.5];
sigma = [1 0.2 0.7;0.2 1 0.5;0.7 0.5 1];
R=cell(5000,1);
for k=1:5000
R{k} = mvnrnd(mux,sigma,40);
end
Look at
doc cell

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!