Generationf of uniform random
古いコメントを表示
How can I generate the uniform random array with the constraint of second value not changing more than 20% of the first value
for example (0.5 0.45 0.54 0.63 0.52...........) The difference between first random to second random should be within 20% of first value and the overall random should in uniform manner.
Thank You.
3 件のコメント
Star Strider
2017 年 11 月 10 日
If you impose constraints, that seems then to make it non-random.
Walter Roberson
2017 年 11 月 10 日
The values after the first are all to be within 20% of the first? Or the values after the first each have to be within 20% of the immediately proceeding value?
htet wai
2017 年 11 月 10 日
採用された回答
その他の回答 (1 件)
Kaushik Lakshminarasimhan
2017 年 11 月 10 日
編集済み: Kaushik Lakshminarasimhan
2017 年 11 月 10 日
This should work:
N=10; % number of random numbers
success = false;
while ~success
x = rand(N,1);
[minval,minindx] = min(abs(x(2:end) - x(1)));
if minval < 0.2*x(1)
x([2 minindx+1]) = x([minindx+1 2]);
success = true;
end
end
disp(x);
Note that as Star Strider pointed out the sequence will no longer be random.
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!