Plotting a function with two terms or alternatively a curve of best fit to a histogram
2 views (last 30 days)
Show older comments
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 Comments
Torsten
on 2 Apr 2020
Edited: Torsten
on 2 Apr 2020
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.
Answers (1)
the cyclist
on 31 Mar 2020
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.
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!