DistributionFit

Fits normal, lognormal, and weibull distributions to data.
6.5K Downloads
Updated 8 Jun 2005

No License

function [pdffit,offset,A,B,resnorm,h] = distributionfit(data,distribution,nbins)

PURPOSE jdc rev. 06-jun-05
Fit one of three probability distributions (normal, lognormal, weibull) to input data vector. If the distribution is specified as 'best' the distribution that best fits the data is selected automatically.

INPUT
If nargin==1, "distribution" is prompted for and entered interactively

data - n x 1 or 1 x n input data vector
distribution - probability distribution to fit to "data". Can be 'normal', 'lognormal', 'weibull', or 'best' ... default: 'best'
nbins - number of bar-chart bins ......................... default: sqrt(length(data))

%OUTPUT
pdffit - fitted probability density function - n x 2 matrix with column 1 the x-values, column 2 the y values
offset - amount by which the data was offset for lognormal or weibull fits (to satisfy the positive-definite requirements for these distributions).

Note: this is roughly equivalent to fitting a 3- rather than a 2-parameter distribution.

A,B - distribution parameters - mu and sigma for normal and lognormal distributions, scale and shape parameters for weibull distribution
h - handles to the bar chart and probability density curve

TYPICAL FUNCTION CALLS
distributionfit(randn(10000,1));
distributionfit(wblrnd(2,3,10000,1));
distributionfit(wblrnd(2,3,10000,1),'weibull');
distributionfit(lognrnd(1.5,.5,10000,1),'lognormal');
distributionfit(lognrnd(1.5,.5,10000,1),'best');
distributionfit(lognrnd(1.5,.5,10000,1),'lognormal');

REFERENCE
Statistics Toolbox Version 3.0.2, function HISTFIT.M

Cite As

J. David Cogdell (2026). DistributionFit (https://www.mathworks.com/matlabcentral/fileexchange/7801-distributionfit), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Probability Distributions and Hypothesis Tests in Help Center and MATLAB Answers
Version Published Release Notes
1.0.0.0