plot pdf along with data

1 次查看(过去 30 天)
Rini
Rini 2016-9-28
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 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by