generate random numbers outside a range

13 ビュー (過去 30 日間)
Omar Hammouda
Omar Hammouda 2017 年 2 月 16 日
コメント済み: Omar Hammouda 2017 年 2 月 16 日
How can I generate random numbers outside a specific range? I want to generate random numbers outside the interval of [-1,3]
  2 件のコメント
Adam
Adam 2017 年 2 月 16 日
Up to what bounds? Generating unbounded random numbers is somewhat problematic.
Omar Hammouda
Omar Hammouda 2017 年 2 月 16 日
I thought about a solution, want to know if there could be better
lets say the numbers I want are between (-11,-1) and (3,13) and I need 5 numbers
xtemp(:,1) = (-1+11).*rand(5,1)-11; %picks a random number from the 1st interval
xtemp(:,2) = (13-3).*rand(5,1)+3; %picks a random number from the 2nd interval
for i=1:5
x(i,1) = xtemp(i,randi(2))
end

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

採用された回答

KSSV
KSSV 2017 年 2 月 16 日
a = -10;
b = 10;
r = (b-a).*rand(1000,1) + a;
%%remove the range [-1 3]
r1 = r ;
r1(r>=-1 & r<=3) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by