
%% ASSUMES THAT D HAS BEEN CREATED. SEE two_random_normal_sets.m 
obj = gmdistribution.fit(D(:,1),2);
idx = cluster(obj,D(:,1));
cluster1 = D(idx == 1,1);
cluster2 = D(idx == 2,1);

%%%% GRAPH: taken from my k-means code. See if it works here.

plot(D(idx==1,1),D(idx==1,2),'r.','MarkerSize',12)
hold on
plot(D(idx==2,1),D(idx==2,2),'b.','MarkerSize',12)
legend('Cluster 1','Cluster 2',...
       'Location','NW');
