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?

답변 (1개)

Matt J
Matt J 2013년 6월 4일
편집: Matt J 2013년 6월 4일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

질문:

2013년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by