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

 채택된 답변

Jos (10584)
Jos (10584) 2014년 3월 4일
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

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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

질문:

2014년 3월 4일

댓글:

2014년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by