I appreciate if anyone could help me with this problem

1 Ansicht (letzte 30 Tage)
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 Kommentare
Raj
Raj am 19 Apr. 2019
Problem statement is pretty straightforward. What exactly is the issue here? Can you share what you have tried so far on this?
Abdelmalek Benaimeur
Abdelmalek Benaimeur am 19 Apr. 2019
when it comes to order numeric values it's nor a problem but
ordering names is where i found the problem
so if it is really straightforward, please show me how

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Raj
Raj am 19 Apr. 2019
Bearbeitet: Raj am 19 Apr. 2019
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 Kommentare
Raj
Raj am 19 Apr. 2019
Sorry! Will take care.
Abdelmalek Benaimeur
Abdelmalek Benaimeur am 19 Apr. 2019
Bearbeitet: Abdelmalek Benaimeur am 19 Apr. 2019
well sir I don't know if you will believe me or not but when i read your answer
you gave me a hint so i took my laptop and i started trying to find the solution
i know that you know the solution but you wanted me to try first
and you have all my respect,
anyway thank you both

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 19 Apr. 2019
Hint: Use sort().
  2 Kommentare
Abdelmalek Benaimeur
Abdelmalek Benaimeur am 19 Apr. 2019
could you please give me the command i should use because i know how to order numeric values only with this function
madhan ravi
madhan ravi am 19 Apr. 2019
Bearbeitet: madhan ravi am 19 Apr. 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by