Filter löschen
Filter löschen

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

28 Ansichten (letzte 30 Tage)
Sahil
Sahil am 18 Aug. 2022
Kommentiert: James Tursa am 10 Mai 2023
create an array of 100 random numbers (Use randi() function) and sort the numbers in ascending order.
  2 Kommentare
KSSV
KSSV am 18 Aug. 2022
What have you attempted for this simple question?
Read about randi, sort
Jan
Jan am 18 Aug. 2022
@Sahil: What is your question? The terms "randi" and "sort" occur in the text. There are Matlab commands with the same names.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ishan Ghosekar
Ishan Ghosekar am 25 Aug. 2022
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 Kommentare
James Tursa
James Tursa am 10 Mai 2023
I suppose you could write your own sorting function. There are many algorithms available.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Shifting and Sorting 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!

Translated by