Create variable with probability it is within a range of value

Hi,
I would like to ask how to create variable x for i period that has following characteristic. In every period, there is 5% that x is within [1:1:5], 5% x is within [6:1:10] and 90% x is within [11:1:100]
My variable is integer and every values within one range has equal probability
Thanks a lot in advance

 Accepted Answer

Take a look at my function RANDINTERVAL. The statement:
X = floor(randinterval([N,1],[1 6 11 101],[5 5 90]))
This will draw N values between 1.0 and 100.99. 5% will be between 1.0 and 5.99… , 5% will be between 6.0 and 10.99… , and 90% will be between 11.0 and 100.99… . By taking the floor you get the desired integers.

2 Comments

Thanks for your answer! But I can't find this function on my matlab version (matlab7 r2009a). I hope I can have it on my university's computers
It is a function that a matlab user (i.e., me) has contributed to the Matlab File Exchange. You should download it (following the link above) and put the m-file in a directory matlab has access to.
Follow these steps:
  1. create a folder/directory on your drive, e.g., D:\MyMFiles
  2. add this folder to the matlab path (File -> Path)
  3. download the zip-file and unzip it
  4. move the m-file to the folder you created in step 1
Step 1 and 2 you only have to do once. You can add other m-files to that folder. This is how you build your own library of functions that are useful to you.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 4 Mar 2014

Commented:

on 5 Mar 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!