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

 Respuesta aceptada

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 comentarios

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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 4 de Mzo. de 2014

Comentada:

el 5 de Mzo. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by