Random number from 1 to 100 if the number between 20 to 30 add 100 if the number 50 to 60 minus 100.
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi guys,
I generated random number 1 to 100.
but i don't know how to change value for 20 to 30 and 50 to 60.
댓글 수: 0
답변 (1개)
John D'Errico
2020년 9월 13일
I'll generate 10 samples.
N = 10;
X = randi(100,1,N);
ind = (X >= 20) & (X <= 30);
X(ind) = X(ind) + 100;
ind = (X >= 50) & (X <= 60);
X(ind) = X(ind) - 100;
The only circumstance where what I did may have been a problem is if the first transformation could move a number from the interval [20,30] into the interval [50,60].
But clearly that could never happen under your constraints.
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!