Help with Sorting Numbers?

I've been asked to create a while loop that will sort all the randomly generated integers from smallest to largest. I'm given this code:
quantity = input(‘Please enter the number of random integers you would like to sort:\n’);
numbers = randi(100,1,quantity);
Could I have some help please? I have no idea where to start with this. Thank you.

Réponses (1)

Ameer Hamza
Ameer Hamza le 30 Avr 2020

2 votes

If this is not a homework question, then you can simply use sort(): https://www.mathworks.com/help/matlab/ref/sort.html
result = sort(numbers)
If it is a homework question, then I cannot write the code, but I can point you to resources where you can study the implementation of other people and then write your own code for your assignment. See this FEX submission: https://www.mathworks.com/matlabcentral/fileexchange/52077-simple-sorting-methods. It provides MATLAB implementations of different sorting algorithms. You can read more about these algorithms from the following links

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by