Ploting the result of a fitgmdist (of 1D data)
17 views (last 30 days)
Show older comments
Marin Vojkovic
on 27 May 2020
Commented: Jeff Miller
on 27 May 2020
I've seen something similar answered a few times here, but none of the solutions work for me.
I have 1D data that I want to fit as 3 Gaussian functions. So, I do a simple:
Fit=fitgmdist(AbsY,3);
The problem now is that I cannot display this. One of the answers on here proposed something like this:
figure
plot(AbsX,AbsY)
hold on
ezcontour(@(x,y)pdf(Fit,[x y]))
But this produces all kinds of errors.
The examples I've seen on the web use the pdf function, but I don't really understand what the second argument should be? Is that the x values of my series? Or the peaks of my Gaussians? Or something else? Also, do I plot it with 'plot', or 'ezcontour' or something else?
Any help with this would be greatly appreciated.
P.S. Maybe I'm too beginner to understand, but the web page for this function is super useles... It only gives examples with contour plots and 2D, and for visualization the first example is:
gmPDF = @(x1,x2)reshape(pdf(GMModel,[x1(:) x2(:)]),size(x1));
g = gca;
fcontour(gmPDF,[g.XLim g.YLim])
Which I cannot make heads or tails of... What are x1 and x2? What does the @ at the start do? Where did g.XLim and g.YLim come from?
0 Comments
Accepted Answer
Jeff Miller
on 27 May 2020
Say you want to plot the distribution from -15 to 15 in steps of 0.05. This would be the code:
z = (-15:0.05:15)'; % Note the crucial '
pdfz = pdf(Fit,z);
figure;
plot(z,pdfz);
Just fill in your desired range and step size instead of -15, 15, and 0.05
2 Comments
Jeff Miller
on 27 May 2020
To get the blue and red curves on the same scale, plot the blue histogram with an option like 'Normalization','pdf' (from memory). The pdfz values your plotting integrate to one, as they should, but the integral of the blue curve looks to be millions. In essence, pdfs are not sensitive to sample size, but histograms are.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!