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 日

0 投票

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 件のコメント

Phat
Phat 2014 年 3 月 4 日
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
Jos (10584)
Jos (10584) 2014 年 3 月 5 日
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 ExchangeDownloads についてさらに検索

タグ

質問済み:

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