Generate three dimensional arrays using mvnrnd in Matlab?

3 Ansichten (letzte 30 Tage)
MRC
MRC am 9 Mai 2014
Kommentiert: dpb am 9 Mai 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?

Antworten (1)

dpb
dpb am 9 Mai 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 Kommentare
MRC
MRC am 9 Mai 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 am 9 Mai 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by