How to generate just one random number in every iteration of for loop?
3 次查看(过去 30 天)
显示 更早的评论
I need to generate just one random number in every iterations.
For i=1:10
x(i)=rand(1)
end
%For example when i=4 (x(4)), this code generate 4 random x which is not my favorite i want just another random x
0 个评论
采纳的回答
Robert Cumming
2014-7-27
Your storing each random created in each loop, if you only want one just do
x = rand (1);
2 个评论
Robert Cumming
2014-7-27
That's what you have in your original code.
At i=4 its generating the 4th random number and saving it in x(4). X(1:3) are already populated by the earlier loops.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!