Generate three dimensional arrays using mvnrnd in Matlab?

5 visualizaciones (últimos 30 días)
MRC
MRC el 9 de Mayo de 2014
Comentada: dpb el 9 de Mayo de 2014
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?

Respuestas (1)

dpb
dpb el 9 de Mayo de 2014
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 comentarios
MRC
MRC el 9 de Mayo de 2014
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 el 9 de Mayo de 2014
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by