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

3 visualizaciones (últimos 30 días)
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 comentarios
Alice Gold
Alice Gold el 2 de Abr. de 2020
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 el 2 de Abr. de 2020
Editada: Torsten el 2 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 31 de Mzo. de 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.

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by