1.0

1.0 | 1 rating Rate this file 2 Downloads (last 30 days) File Size: 1.22 KB File ID: #26608

Generation of random number given the pmf

by Furlan

 

06 Feb 2010 (Updated 09 Feb 2010)

n=rand_gen(x,pmf,N) Generates a random signal n oh length N from a desird pmf.

| Watch this File

File Information
Description

n=rand_gen(x,pmf,N)

esample :
x=[1,3,4] : set of variables
pmf=[1/3,1/3,1/3] : [rpbability of each variable of x
N=100 : number of samples of the random signal

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
08 Feb 2010 Jos (10584)

The lack of any help, comments, % symbol what so ever and the unvectorized engine makes this is poor submission. Finally, this functionality is already available here on the File Exchange.

08 Feb 2010 Furlan

I submitted a new version whit the help comments and
a vectorial engine.
Brg
Ivan

09 Feb 2010 Michael Chen

please see
http://www.mathworks.com/matlabcentral/fileexchange/25481-discrete-multinomial-distribution-sampler
which is simpler and faster.

09 Feb 2010 Jos (10584)

The help is certainly an improvement! You could add an H1 line to assist users of LOOKFOR.

However, floating point issues are not dealt with properly : rand_gen(x,[.1 .2 .3 .3 .1],N) returns an unexpected error .

And, as Michael Chen already pointed out, there are many alternatives on the FEX, including my own:
http://www.mathworks.com/matlabcentral/fileexchange/8891

09 Feb 2010 Furlan

Yes the check 'sum(pmf)==1' causes problem.
To avoid the unexpected error, I eliminated the check In the new submitted version.
Thank you for your suggestions.

Please login to add a comment or rating.
Updates
08 Feb 2010

1) Eliminated the cycle for (vectorial engine now)
2) Added the help

08 Feb 2010

1)Vectorial engine
2) added the help

09 Feb 2010

Eliminated the check sum(pmf)==1

Tag Activity for this File
Tag Applied By Date/Time
random signals generation Furlan 08 Feb 2010 11:37:10
random signals generation Agustin Pimstein 05 Mar 2010 13:15:31

Contact us at files@mathworks.com