How do I fit multiple Gaussians to my data?
조회 수: 14 (최근 30일)
이전 댓글 표시
I have 1D data that I want to fit as 3 (possibly more) Gaussian functions. So, I do a simple:
Fit=fitgmdist(AbsY(242:654),3);
z = AbsX(340:580);
pdfz = pdf(Fit,z);
plot(z,pdfz);
figure
plot(AbsX,AbsY)
hold on
plot(z,pdfz);
But the output I get is not what I'm looking for. The script runs and it's ok, but hte output looks like this:
The fit functions overlap, so it seems it's only one line, and their magnitude is way too low.
The examples I've seen on the web and here on Answers use this function, and it's recommended everywhere as a solution to this kind of problems, and it makes sense.
So, what am I doing wrong here?
Any help with this would be greatly appreciated.
I managed to do it in Origin, so the result should be something like this:
Ok, here's 4 Gaussians, but that's besides the point for the moment. How do I get this in Matlab please?
댓글 수: 0
답변 (1개)
Jeff Miller
2020년 5월 28일
From the new graph you've posted, it looks like the values in AbsY are not the type of data expected by fitgmdist, and I suspect it isn't actually the right tool for getting you the fit you want. Just to be sure: fitgmdist expects data x that is just one big long list of values for a dependent variable. Think of, for example, the individual heights of a large random sample of people. So, fitgmdist is trying to model the frequency distribution of those x's, i.e., "how often does each of the different possible values appear within the x array?"
It looks like your numbers in AbsY are something else entirely--I'm guessing they are the heights of an intensity function at a certain wavelength. Whatever they are, it looks like you are trying to model a function relating AbsX to AbsY, which is a different kind of problem entirely, because you don't want to describe the counts of AbsY, you want to describe their relation to AbsX.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!