Search code examples
matlabrandomdata-fitting

How can i randomly sample from a distribution already fitted with allfitdist in MATLAB?


I 've found the best fitting of a variable distribution (D(:,2)) using the function "allfitdist". Now i want to save this result in a structure and then i want to randomly sample 10000 times from this result. I'm using this code:

[Ddg2 PDdg2] = allfitdist(D(:,2),'cdf')
My(2).result = PDdg2{1,1} %generalized pareto
output = random(My(2).result,10000)

Something is weard because in the output i get a really big matrix. Maybe i'm wrong in the third raw of the code, when i randomly sample from this distribution. Someone can help me?


Solution

  • The documentation of random says:

    R = random(___,sz1,...,szN) or R = random(___,[sz1,...,szN]) generates a sz1-by-⋯-by-szN array of random numbers from the specified probability distribution using input arguments...
    ...
    If you specify a single value sz1, then R is a square matrix of size sz1.

    You have specified sz1 as 10000 which is a single value and hence your output matrix is 10000×10000.

    So the solution is:

    output = random(pd,1,10000);