MATLAB: Problem when plotting the figure

pdf plotplot figure

I have a vector called K [622×1] double I plot the PDF of K . I fitted my K vector to the Gaussian mixture distribution and ploted the PDF with a solid line :
>> GMModel = fitgmdist(k,2);
>> gm=gmdistribution(GMModel.mu,GMModel.Sigma);
>> pdfk=pdf(gm,k);
>> figure
>> plot(k,pdfk)
The plot has several lines and I dont know what is the problem and how to resolve it. Ca anyone help me with this? thank youuu

Best Answer

I do not have ‘k’, so I created my own, and was able to reproduce essentially the result you got.
The multiple lines disappear of you sort ‘k’ first:
k = sum([randn(622,1)+5; randn(622,1)+1],2);
k = sort(k); % <— ADD ‘sort’ CALL
GMModel = fitgmdist(k,2);
gm=gmdistribution(GMModel.mu,GMModel.Sigma);
pdfk=pdf(gm,k);
figure
plot(k,pdfk)
.
Related Question