Plotting a function with two terms or alternatively a curve of best fit to a histogram

조회 수: 2 (최근 30일)
Hello,
I have a data set (H) that I have plotted on a histogram (Hist). The histogram displays a bimodal distribution.
The histogram includes some negative values on the x-axis. The values for the y-axis are not from data I have in my workspace but instead the frequency of my x-vales that was calculated by the histogram function.
I would like to fit a curve to this histogram that has the function :
f = @(A,m,s,H) A(S) * exp(-((H-m(S))/s(S)).^2) + A(S2) * exp(-((H-m(S2))/s(S2)).^2)
Alternatively, any solution that would allow me to fit a curve of best fit to this data would amazing.
I have trawlled all the forums but haven't found a solution that works.
Any help would be greatly appriciated.
  댓글 수: 5
Alice Gold
Alice Gold 2020년 4월 2일
Ohhh I see what you mean - I was only extracting only the y and not the x values from the histogram! This has now worked! Thank you for your help!
Torsten
Torsten 2020년 4월 2일
편집: Torsten 2020년 4월 2일
You can't use curve fitting for this kind of problem since the fitting parameters will strongly depend on the bin width.
Although it might be hard statistics for a beginner, you should read about maximum likelihood estimation and use Matlab's "mle" or the tools for which "the cyclist" provided links.
Wikipedia's article about "Probability distribution fitting" is a good starting point.

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2020년 3월 31일
If you have all of the x values, then you should be able to fit using the fitgmdist function, which will find the best fit to multiple gaussians. You won't need to specify your function.
If you have only the bin locations and counts, then you should be able to use the fitnlm function. You will need to specify your function in this case.
Both of these functions are from the Statistics and Machine Learning Toolbox.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by