Generate three dimensional arrays using mvnrnd in Matlab?

조회 수: 4 (최근 30일)
MRC
MRC 2014년 5월 9일
댓글: dpb 2014년 5월 9일
I need to generate a three dimensional matrix B in Matlab using the command mvnrnd. In particular, let
mu=[0 0; -1 -3; 0 4; 2 4; 8 1]
and
sigma=repmat(1/(3^2)*eye(2),[1,1,5])
If I use the command
B= mvnrnd(mu,sigma)
I get a matrix 5x2 in which each row i is sampled from N(mu(i,:), sigma(:,:,i)). Instead, I want B to be 5x2xr, i.e. each row i is sampled from N(mu(i,:), sigma(:,:,i)) r times.
Could you help me?

답변 (1개)

dpb
dpb 2014년 5월 9일
From
help mvnrnd
...
R = mvnrnd(MU,SIGMA,N) returns a N-by-D matrix R of random vectors
chosen from the multivariate normal distribution with 1-by-D mean
vector MU, and D-by-D covariance matrix SIGMA.
  댓글 수: 2
MRC
MRC 2014년 5월 9일
let n=10 for example. Then by typing mvnrnd(mu,sigma,N) I get this error
??? Error using ==> mvnrnd at 76
MU must be a row vector, or must have CASES rows.
dpb
dpb 2014년 5월 9일
Well, I should've read the doc all the way thru... :)
The third option doesn't replicate into a 3D sampling after all; it's still a 2D array returned.
Looks like you'll have to wrap the call in a loop to populate the planes or use accumarray w/ an anonymous function wrapper around the 2D result by plane.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by