Generate n independent multivariate normal?

1 view (last 30 days)
How can we write a Mathlab function to generate n independent multivariate normal N(mu,Sigma)?
I knows it is kinda easy if I just use the new syntax by putting the function as X = mvnrnd(MU,SIGMA,cases)
However, this is my code, I am not sure why it can't work?
function X = myrandn(n,mu,Sigma)
d = length(mu);
R = chol(Sigma);
Z = randn(n,d);
X = Z*R + ones(n,1)*mu';
The command window keeps referring that:* Error using myrandn (line 5). Not enough input arguments.* The line 5 here refering to the d=length(mu).
Any ideas which part of the code is wrong or perhaps any pointers that what is the reason for this error to appear?

Answers (1)

Matt J
Matt J on 4 Jun 2013
Edited: Matt J on 4 Jun 2013
You aren't calling myrandn() with 3 input arguments.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!