How can I sort an array with two columns?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
If I have an array of student ID in column1 and GPAs in column2
Info = [52211 3.55; 52922 1.79; 51939 3.33; 12140 0.81]
How can I sort the array from the highest GPA to the lowest GPA.
0 Commenti
Risposta accettata
Più risposte (2)
KSSV
il 8 Ott 2018
Info = [52211 3.55; 52922 1.79; 51939 3.33; 12140 0.81] ;
[val,idx] = sort(Info(:,2),'descend') ;
iwant = Info(idx,:)
0 Commenti
Kevin Chng
il 8 Ott 2018
Hi,
Info = [52211 3.55; 52922 1.79; 51939 3.33; 12140 0.81];
[~,I] = sort(Info(:,2),'descend');
Info(I,:);
Done!
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!