www.gusucode.com > stats 源码程序 matlab案例代码 > stats/SimulateDataFromAGaussianMixtureModelExample.m

    %% Simulate Data from a Gaussian Mixture Model
% This exampe shows how to simulate data from a Gaussian mixture model
% (GMM) using a fully specified <docid:stats_ug.btdocli
% gmdistribution> object and <docid:stats_ug.brx2uz9-1 random>.
%% 
% Create a known, two-component GMM object.

% Copyright 2015 The MathWorks, Inc.

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');