Generating random numbers using for loop
18 次查看(过去 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!