random integers in a customized ranges

to find 100 random integers between 1 and 5000 we use: x = randi(5000,100,1); is there a way to find random integers between 1 and 5000 excluding the numbers between 2000 and 25000 and between 4000 and 4500 for example thank you

 採用された回答

KSSV
KSSV 2018 年 6 月 6 日

0 投票

x = randi(5000,1000,1); % make more number of random integers
% remove the unwanted
x(x>=2000 & x<=2500) = [] ;
x(x>=4000 & x<=4500) = [] ;
% now pick 100 out of it
idx = randperm(length(x),100) ;
iwant = x(idx) ;

1 件のコメント

Dam
Dam 2018 年 6 月 12 日
thank you very much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

Dam
2018 年 6 月 6 日

コメント済み:

Dam
2018 年 6 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by