How can we generate random numbers between two negative values.
조회 수: 29 (최근 30일)
이전 댓글 표시
Can some plz help me to generate random nos between two negative values like [-5,-1.670000000000000]
댓글 수: 0
채택된 답변
KSSV
2021년 1월 11일
a = -5 ;
b = -1.670000000000000 ;
r = (b-a).*rand(1000,1) + a;
댓글 수: 4
Steven Lord
2021년 1월 11일
The randi function generates random integer values in a specified range. Nothing about the function limits it to only being able to produce random positive integer values.
allPositive = randi([2 10], 1, 5)
allNegative = randi([-10 -2], 1, 5)
mixedSigns = randi([-6 6], 1, 5)
If you want to generate normally distributed or uniformly distributed numbers, see the documentation pages for the randn and rand functions respectively.
추가 답변 (0개)
참고 항목
카테고리
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!