Generating random numbers using for loop
조회 수: 34 (최근 30일)
이전 댓글 표시
Hi, Shall i use the following code to generate random numbers and use them further in the calculation?
clear all
close all
for n=1:2;
h(n)=rand
end
채택된 답변
Walter Roberson
2019년 2월 7일
If you like. you could instead pass size information to rand to say how many items to generate .
추가 답변 (2개)
Image Analyst
2022년 6월 18일
@Maheen Fazal did you look at the help? If you would, you'd see info like this:
Random Numbers Within Specified Interval
Generate a 10-by-1 column vector of uniformly distributed numbers in the interval (-5,5).
r = -5 + (5+5)*rand(10,1)
So, for you:
h = rand(1, 2)
댓글 수: 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!