Help with Sorting Numbers?
Show older comments
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.
Answers (1)
Ameer Hamza
on 30 Apr 2020
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
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!