Generate n independent multivariate normal?
1 view (last 30 days)
Show older comments
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?
0 Comments
See Also
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!