Generate n independent multivariate normal?

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?

Réponses (1)

Matt J
Matt J le 4 Juin 2013
Modifié(e) : Matt J le 4 Juin 2013

0 votes

You aren't calling myrandn() with 3 input arguments.

Catégories

En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange

Question posée :

le 4 Juin 2013

Community Treasure Hunt

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

Start Hunting!

Translated by