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!