Creating an array of random numbers and sorting them in ascending order

조회 수: 90 (최근 30일)
Sahil
Sahil 2022년 8월 18일
댓글: James Tursa 2023년 5월 10일
create an array of 100 random numbers (Use randi() function) and sort the numbers in ascending order.
  댓글 수: 2
KSSV
KSSV 2022년 8월 18일
What have you attempted for this simple question?
Read about randi, sort
Jan
Jan 2022년 8월 18일
@Sahil: What is your question? The terms "randi" and "sort" occur in the text. There are Matlab commands with the same names.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ishan Ghosekar
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
Shailendra Shankar 2023년 5월 9일
@Ishan Ghosekar: how would you sort without using the sort function.
James Tursa
James Tursa 2023년 5월 10일
I suppose you could write your own sorting function. There are many algorithms available.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by