EMPRAND generates random numbers from empirical distribution of data. This is useful when you do not know the distribution type (i.e. normal or uniform), but you have the data and you want to generate random numbers form that data.
The idea is to first construct cumulative distribution function (cdf) from the given data. Then generate uniform random number and interpolate from cdf.
USAGE:
[xr] = emprand(dist) generates single random number from given vector of data values dist.
[xr] = emprand(dist,m) generates m by m matrix of random numbers.
[xr] = emprand(dist,m,n) generates m by n matrix of random numbers.
Examples:
% Generate 1000 random normal numbers as data for EMPRAND
dist = randn(1000,1);
% Now generate 2000 random numbers from this data
xr = emprand(dist,2000,1);
Durga Lal Shrestha (2021). Random Number from Empirical Distribution (https://www.mathworks.com/matlabcentral/fileexchange/7976-random-number-from-empirical-distribution), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Thank you it also saved my time :)
Thank you, saved some time!
Hi Durga and everyone,
I have the same problem, but my data lives in an 18-dimensional space. Can I adapt this or would the time/memory explode to do this?
Thank you,
I have the same problem as Israa, matlab can't recognize this function. why??
I tried it many times, but not working I keep getting this error:
" Undefined function 'emprand' for input arguments of type 'double'."
I even checked my path and everything is all right but still not working
It works well but i am getting 'NaN' in my final results. how to fix that? Also how is empcdf different from ecdf? thanks
Nice job. Saved me some work when I realized I had a need for this functionality.
It is good for Bootstrap!