File Exchange

image thumbnail

Random Number from Empirical Distribution

version 1.0.0.0 (3.12 KB) by Durga Lal Shrestha
Generates random numbers from empirical distribution of data

10 Downloads

Updated 04 Apr 2016

View License

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);

Comments and Ratings (9)

amol mankar

Thank you it also saved my time :)

Thank you, saved some time!

Paulo Abelha

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,

Nan Li

I have the same problem as Israa, matlab can't recognize this function. why??

Israa

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

dave dave

It works well but i am getting 'NaN' in my final results. how to fix that? Also how is empcdf different from ecdf? thanks

nasos asimakopoulos

Keith McCarron

Nice job. Saved me some work when I realized I had a need for this functionality.

Tang Yayong

It is good for Bootstrap!

Updates

1.0.0.0

BSD License

1.0.0.0

Improvement, bug fixes and simplify the code

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux