I appreciate if anyone could help me with this problem
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a list of students , every student has a grade (numeric value)
how can i order the list of those students according to their marks ,
so that the first one in the list is the one who has the highest grade
for example (let's assume that the grades are between 0 and 20)
Alex: 19
Morgan: 12
Erik: 15
Montana:13
Molko:10
Kelsie:16
the list should be lik that
Alex Kelsie Erik Montana Morgan
댓글 수: 2
Raj
2019년 4월 19일
Problem statement is pretty straightforward. What exactly is the issue here? Can you share what you have tried so far on this?
채택된 답변
Raj
2019년 4월 19일
편집: Raj
2019년 4월 19일
Name = {'Alex';'Morgan';'Erik';'Montana';'Molko';'Kelsie'};
Marks = [19;12;15;13;10;16];
% Create a table
InputTable = table(Name, Marks)
% Sort rows of the table
SortedTable = sortrows(InputTable, 2)
Temp_List=SortedTable(:,1)
Required_List=flip(Temp_List)
As I said, It's straighforward. Hope this helps!
댓글 수: 3
추가 답변 (1개)
madhan ravi
2019년 4월 19일
Hint: Use sort().
댓글 수: 2
madhan ravi
2019년 4월 19일
편집: madhan ravi
2019년 4월 19일
Just use a cell array to contain each name and corresponding grades in each row of the cell array . Sort the grades which is in the second column. Assign the second output of sort as the row subscript for the cell array thereby sorting your cell array according to the given homework. If you are still not able to figure out, post the code that you tried to get further help.
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!