control the threshold of random numbers
이전 댓글 표시
I want to control the threshold of random numbers. In following code 1st column I want more on higer side e.g more (0.5 to 0.9 and less 0.1 to 0.5). In second column I want more 1s than 0s.
code:
Carr_veh = [rand(100, 1), randi([0, 1], 100, 1 )]
채택된 답변
추가 답변 (1개)
Yongjian Feng
2021년 7월 1일
Hello abdul,
Both rand and randi generate uniformly distributed pseudorandom numbers. Now you want something not uniformly distributed, but you didn't specify what kind of distribution you are looking for.
One possible way to do it is to scale the generated random number. For example, instead of randi([0,1], 100, 1]), use randi([0,2], 100, 1). Then add an additional logic
if res == 2
res = 1;
end
By doing so, there are twice 1s than 0s.
Similar idea for rand(100, 1). You can scale (0, 0.3) to (0, 0.5) and (0.3, 1) to (0.5, 1). By doing so, you have 30% (0, 0.5) and 70% (0.5, 1)
Thanks,
Yongjian
카테고리
도움말 센터 및 File Exchange에서 Univariate Discrete Distributions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


