Generating random numbers in order?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joe
am 7 Apr. 2013
Kommentiert: Walter Roberson
am 9 Dez. 2021
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 Kommentare
Akzeptierte Antwort
Roger Stafford
am 7 Apr. 2013
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');
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!