MATLAB: I have Statistics and Machine Learning Toolbox but cannot use allfitdist

allfitdiststatisticsStatistics and Machine Learning Toolbox

I tried running a script I found on http://blogs.mathworks.com/pick/2012/02/10/finding-the-best/ to learn how to find the best distribution fit. When I run the script
% Create a normally distributed (mu: 5, sigma: 3) random data set
x = normrnd(5, 3, 1e4, 1);
% Compute and plot results. The results are sorted by "Bayesian information % criterion".
[D, PD] = allfitdist(x, 'PDF');
I get this error message:
Undefined function or variable 'allfitdist'.
Error in Find_best_distribution (line 7) [D, PD] = allfitdist(x, 'PDF')
I tried using the ver command to confirm that I have the Statistics toolbox and got this:
MATLAB Version 9.0 (R2016a) Statistics and Machine Learning Toolbox Version 10.2 (R2016a)
I also tried the disttool command and that worked.
Why can I not run allfitdist?
Thanks, Josefin

Best Answer

Did you download allfitdist.m from the file exchange? This is not a Mathworks function. If you go back to the blog, there is a link that will take you to the file exchange for allfitdist. Download the file and make sure that you put it in a folder on your path