using rand to generate numbers
1 次查看(过去 30 天)
显示 更早的评论
Hi
I have a simple question. I understand that both a and b vectors (please see below) will generate 5 random numbers from 0 to 5 with an interval of 1 between each number. But I would like to know if there is any difference between vectors a and b or if they have the same meaning.
N=5;
a = [0:N-1]+rand(1,N)/N;
b = [0:N-1]+rand/N;
Thank you
0 个评论
采纳的回答
the cyclist
2013-9-4
Is this homework?
If so, I suggest you read
doc rand
and see what the difference is between the syntax
rand(1,N)
and
rand
2 个评论
更多回答(1 个)
Shashank Prasanna
2013-9-4
编辑:Shashank Prasanna
2013-9-4
Try executing it and seeing it for yourself.
rand just generats one random number and adds it to each element of the vector: [0:N-1]
where as rand(1,N) generates N random numbers and adds them element wise to the vector: [0:N-1]
They are obviously different. Is that what you are looking for?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!