MATLAB Examples

Simulate Data from a Gaussian Mixture Model

This exampe shows how to simulate data from a Gaussian mixture model (GMM) using a fully specified gmdistribution object and random.

Create a known, two-component GMM object.

Mu = [1 2;-3 -5];
Sigma = cat(3,[2 0;0 .5],[1 0;0 1]);
P = ones(1,2)/2;
gm = gmdistribution(Mu,Sigma,P);

Plot the contour of the pdf of the GMM.

gmPDF = @(x,y)pdf(gm,[x y]);

figure;
ezcontour(gmPDF,[-10 10],[-10 10]);
hold on
title('GMM - PDF Contours');

Generate 1000 random variates from the GMM. Plot the variates with the pdf contours.

X = random(gm,1000);
scatter(X(:,1),X(:,2),10,'.')
title('GMM - PDF Contours and Simulated Data');