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
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by