Generating random numbers in order?
8 次查看(过去 30 天)
显示 更早的评论
How would you generate random numbers so that they are in ascending or descending order? Is there a way to create a function similar to linspace in that it generates linearly spaced values in a certain interval but with random numbers each time you execute the function?
0 个评论
采纳的回答
Roger Stafford
2013-4-7
If a and b are the lower and upper limits you have in mind for the numbers, do this:
x = sort((b-a)*rand(n,1)+a,'ascend' or 'descend');
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!