フィルターのクリア

Generating random numbers in order?

15 ビュー (過去 30 日間)
Joe
Joe 2013 年 4 月 7 日
コメント済み: Walter Roberson 2021 年 12 月 9 日
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?

採用された回答

Roger Stafford
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 件のコメント
Joe
Joe 2013 年 4 月 7 日
Thanks a bunch!

サインインしてコメントする。

その他の回答 (1 件)

NIKHIL KUMAR
NIKHIL KUMAR 2021 年 12 月 9 日
x = sort((10-1)*rand(n,1)+1,'ascend' or 'descend');
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 12 月 9 日
This is the same as what Roger suggested in 2013.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by