Search code examples
matlabdistributionweibull

Generating samples from Weibull distribution in MATLAB


I am using the command wblrnd(12.34,1.56) to get 100 different values that lie within the Weibull distribution with those parameters.

But I want those 100 points/values to have the same distribution as the one given by the parameters. Which doesn't happen.

Basically I want, to get 100 values that give me the exact same distribution I had before.


Solution

  • You cannot have the same distribution as the one you're sampling from, unless the number of draws you perform is infinite.

    To give you a practical example you can compare how the empirical distribution of your draws, i.e. the histogram, matches the fitted pdf:

    subplot(121)
    sample = wblrnd(12.34,1.56,100,1);    
    histfit(sample,100,'wbl')
    title('100 draws')
    
    subplot(122)
    sample = wblrnd(12.34,1.56,1e5,1);    
    histfit(sample,100,'wbl')
    title('100,000 draws')
    

    enter image description here

    Also, note that the mean and standard deviations are NOT the arguments of wblrnd(A,B). In other words, mean(sample) is not supposed to converge to 12.34.

    You can check on wikipedia: weibull distribution how to retrieve the mean from the shape and scale parameters, i.e. what theoretical mean is given by 12.34 and 1.56.