How can I generate random matrices from the multivariate normal distribution using the Statistics Toolbox?
2 次查看(过去 30 天)
显示 更早的评论
I would like to generate random matrices from the multivariate normal distribution using the Statistics Toolbox.
采纳的回答
MathWorks Support Team
2010-1-22
The function mvnrnd.m allows you to generate random matrices from the multivariate normal distribution. This function is included with Statistics Toolbox 3.0 (R12.1) and later versions.
Following is a quick example illustrating MVNRND:
mu1=.5;mu2=1.4;
var1=.9;var2=.6;
cov_desired=.5;
mean_desired=[mu1 mu2]
cov_matrix_desired=[var1 cov_desired;cov_desired var2]
%[R p]=chol(cov_matrix_desired)
% The covariance matrix must be positive definite (pd)
% If p is 0, this is a pd matrix;
% see Solution 1530
M=mvnrnd(mean_desired,cov_matrix_desired,100000);
actual_mean=mean(M)%Close to mean_desired
actual_cov=cov(M)% Close to cov_matrix_desired
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!