[Y,compIdx] = random(___)
also returns an n-by-1 index vector compIdx
for any of the input arguments in previous syntaxes. compIdx(i)
indicates the mixture component used to generate the ith random
variate Y(i,:).
Create a gmdistribution object by using the gmdistribution function. By default, the function creates an equal proportion mixture.
gm = gmdistribution(mu,sigma)
gm =
Gaussian mixture distribution with 2 components in 2 dimensions
Component 1:
Mixing proportion: 0.500000
Mean: 1 2
Component 2:
Mixing proportion: 0.500000
Mean: -3 -5
Generate 1000 random variates.
rng('default'); % For reproducibility
[Y,compIdx] = random(gm,1000);
compIdx(i) indicates the mixture component used to generate the ith random variate Y(i,:). Count the number of random variates generated by Component1.
numIdx1 = sum(compIdx == 1)
numIdx1 =
512
random generates about half of the random variates using Component1 because gm has equal mixing proportions.
Plot the generated random variates by using scatter.
scatter(Y(:,1),Y(:,2),10,'.') % Scatter plot with points of size 10
The cat function concatenates the covariances along the third array dimension. The defined covariance matrices are diagonal matrices. sigma(1,:,i) contains the diagonal elements of the covariance matrix of component i.
Create a gmdistribution object by using the gmdistribution function.
gm = gmdistribution(mu,sigma);
Save the current state of the random number generator, and then generate a random variate using gm.
s = rng;
r = random(gm)
r = 1×2
-1.1661 -7.2588
Restore the state of the random number generator to s, and then generate a random variate using gm. The values are the same as before.
Gaussian mixture distribution, also called Gaussian mixture model (GMM), specified as a gmdistribution object.
You can create a gmdistribution object using gmdistribution or fitgmdist. Use the gmdistribution function to create a
gmdistribution object by specifying the distribution parameters.
Use the fitgmdist function to fit a gmdistribution
model to data given a fixed number of components.
Number of random variates to generate, specified as a positive
integer.
Random variate, returned as a 1-by-m numeric vector or
an n-by-m numeric matrix. Each row
of Y is a random variate generated from the
m-dimensional Gaussian mixture distribution
gm.
Component index, returned as a positive integer or an
n-by-1 index vector, where
compIdx(i) indicates the mixture component used to
generate the ith random variate
Y(i,:).
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.