Your problem is a not uncommon one for people who don't understand random distributions.
The fact is, you don't have data as samples from a lognormal distribution. You have points taken as values off the lognormal PDF. You cannot use lognfit to fit that data.
Lets see how to do it, in a way that will work. I'll start with a simple example, using a normal.
Here, I'll generate some random samples using randn. The mean should be 2, standard deviation 3. But the estimated values for those parameters will not be exactly those numbers of course since they are estimates, taken from a finite sample.
X = randn(1000,1)*3 + 2;
[MUHAT,SIGMAHAT] = normfit(X)
MUHAT =
1.9021041197117
SIGMAHAT =
2.99689596815649
As you can see, it did pretty well. But you need to recognize that normfit (and the cousin, lognfit that you tried to use) work on points that are assumed to follow that distribution, as I did above.
Random samples that are assumed to follow a given distribution are NOT the same thing as points taken off a PDF.
Best Answer