plot pdf along with data
2 views (last 30 days)
Show older comments
Hi,
I have a 1D array generated from Gaussian mixtures and the estimated mean and variance and mixing weight for each component. How can I plot the data along with the pdf curves for each component. I tried the following code but it produces only the curves which do not fit within the range.
X is the 1D array.
lineStyles={'--b','--g','--r','--c','--m','--y'};
minVal = min(X);
maxVal = max(X);
plotRange = minVal:(maxVal-minVal)/100:maxVal;
hist(X,plotRange);
hold on;
totalProb = zeros(1,length(plotRange));
for i=1:length(model.m) % no. of components. m is estimated mean and W is the inverse covariance matrix
probs = normpdf(plotRange, model.m(i),1./exp(model.logW(i)));
probs = probs./sum(probs);
finalProbs = model.alpha(i)*length(X)*probs; % alpha is the mixing weight for each component
plot(plotRange,finalProbs,lineStyles{mod(i,6)+1},'LineWidth',2);
totalProb = totalProb + finalProbs;
end
plot(plotRange, totalProb, '-k','LineWidth',3);
0 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!