Generate three dimensional arrays using mvnrnd in Matlab?

4 次查看(过去 30 天)
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