How to generate bivariate random normally distributed 3d array?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nainsi Gupta
el 31 de Mayo de 2023
Comentada: Nainsi Gupta
el 1 de Jun. de 2023
mu= [0 0]
sigma= [1 0.25; .25 1]
mvnrnd(mu,sigma,100)
I want to generate a 3-by-2-by-100 array which is normally distributed with given mu and sigma. Please help me how can I do this?
5 comentarios
John D'Errico
el 31 de Mayo de 2023
Since the realizations of such a random variable are i.i.d., it is sort of irrelevant what the 1st and third diemsnions mean!
Respuesta aceptada
John D'Errico
el 31 de Mayo de 2023
Editada: John D'Errico
el 31 de Mayo de 2023
Um, trivial?
You apparently want to generate 300 samples of a bivariate normal. So generate them as a 300x2 array, Then reshape and permute them into the desired 3x2x100 array.
mu= [0 0];
sigma= [1 0.25; .25 1];
X = mvnrnd(mu,sigma,300);
X = reshape(X,[3,100,2]);
X = permute(X,[1 3 2]);
size(X)
3 comentarios
John D'Errico
el 31 de Mayo de 2023
Permute is like transpose. But it applies to arrays of multiple dimensions.
Look at what I did.
mu= [0 0];
sigma= [1 0.25; .25 1];
X = mvnrnd(mu,sigma,300);
What is the initial size of X?
size(X)
I generated 300 samples of bivariate random numbers with the desired distribution. What did reshape do?
X = reshape(X,[3,100,2]);
size(X)
So I simply reshaped that into an array of 3x100 instances of the same random numbers. FInally, the call to permute does nothing more than transpose the second and third dimensions.
X = permute(X,[1 3 2]);
size(X)
Again, permute is just like transpose. It allows you to transpose any dimensions you wish. It applies to 3-d and higher dimension arrays.
You will do exactly the same thing, IF you wanted to generate trivariate random numbers. But now you will have a 3 instead of a 2 in those places in the reshape and permute.
Más respuestas (0)
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!