How to generate a random REAL NUMBER VECTOR with a range?
조회 수: 2 (최근 30일)
이전 댓글 표시
How to generate a random REAL NUMBER VECTOR with a range?
I can only generate a random INTEGER vector with a range, which is randi([low, high], column, row) but I don't know how to create a random number vector with a range... I tried rand([low, high], column, row) and an error message popped out saying "Error using rand Size inputs must be scalar."
댓글 수: 0
채택된 답변
추가 답변 (1개)
Image Analyst
2017년 10월 27일
Try this. I do it both ways: to get integers and floating point numbers. Use whichever you want:
low = 10;
high = 20;
numElements = 80;
% Generate integer vector.
rIntegers = randi([low, high], 1, numElements)
% Generate floating point (fractional) number vector.
rDoubles = low + (high-low) * rand(1, numElements)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!