Creating an array of random numbers and sorting them in ascending order
90 ビュー (過去 30 日間)
古いコメントを表示
create an array of 100 random numbers (Use randi() function) and sort the numbers in ascending order.
2 件のコメント
回答 (1 件)
Ishan Ghosekar
2022 年 8 月 25 日
As I understand, you want to create an array of 100 random numbers using MATLAB randi() function and then sort the random numbers in ascending order.
The following code illustrates how to achieve the above using two MATLAB functions, randi and sort:
a = randi(100, 1, 100); % Creates an array of 100 random numbers.
b = sort (a, 'ascend'); % Sort an array into ascending order.
For more information on these functions,refer to the following documentation links:
2 件のコメント
Shailendra Shankar
2023 年 5 月 9 日
@Ishan Ghosekar: how would you sort without using the sort function.
James Tursa
2023 年 5 月 10 日
I suppose you could write your own sorting function. There are many algorithms available.
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!