File Exchange

image thumbnail

Histogram fitting Probability Density, Counts, Frequency

version (5.1 KB) by Nathan Orloff
A cleaned up version of histfit that outputs data


Updated 02 Jun 2014

View Version History

View License

I modified histfit to output the fit results. I haven't reinvented the wheel here. I just took histfit and fixed it. The usage is the same. I also made it so that it automatically computes the interquartile range ( for each fit. You can also specify the bins if you want. And now you can toggle between plot types: 'pdf', a curve with area 1; 'counts', number of counts; 'percent', put it in frequency.
If you have data that you want to fit to a histogram then use this function. Your data is a vector "data", then plot type. Chose from any of the viable options for the fit. And then the last input sets the plot type.
The output is the handles of the figure, the probability fit object with all the inherited properties, and xydata which is the x and y data to make the bar graph.

Here is an example.
[h,fitobject,xydata] = histfit2(xx,nbins,'lognormal','counts');

Use Freedman-Diaconis rule and plot as counts:
[h,fitobject,xydata] = histfit2(xx,[],'lognormal','percent');

It makes a pretty green bar graph. Have fun.

Cite As

Nathan Orloff (2020). Histogram fitting Probability Density, Counts, Frequency (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Nathan Orloff

Oh it doesn't output the object and it makes a graph of counts instead of probability density. So that was driving me a little crazy.


Hi, looks good, but what exactly is wrong with histfit? Used it many times.

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!