フィルターのクリア

Random Number Generation for Continuously Decrementing Range

3 ビュー (過去 30 日間)
New User
New User 2020 年 10 月 24 日
コメント済み: New User 2020 年 10 月 24 日
How can I generate random numbers within a specific range and that range decrements by a specific number? Furthermore the random numbers generated for the given ranges must be stored in their respective arrays and afterwards a single array must store all those subarrys.

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 24 日
Try this
lb = 0; % initial upper bound
ub = 1; % initial lower bound
n = 10; % number of random point in each interval
x = {}; % cell array forr random numbers in each interval
count = 1;
while (ub-lb)>0
x{count} = rand(1, n)*(lb-ub) + ub;
lb = lb + 0.01; % increase the lowerr bound
ub = ub - 0.01; % decrease the lowerr bound
count = count + 1;
end
y = [x{:}]; % all random numbers
  1 件のコメント
New User
New User 2020 年 10 月 24 日
There is a problem in this code the y array does not follow the trend of decreasing ranges. The distribution of random numbers is random in y. Neverthless thank you very much.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by