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.
回答(1 个)
Ameer Hamza
2020-4-30
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
类别
在 帮助中心 和 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!