Sorting the rows of a 2-column matrix based on entries from one column.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Kyle Reagan
il 16 Giu 2017
Commentato: Kyle Reagan
il 16 Giu 2017
I have a matrix with two columns. The first column is numbers and the second is a string of words. I want to sort the entire matrix in ascending order based on the first column entries and without losing each number's second column pair. A simplified example is as follows:
4 Apple
3 Orange
6 Pear
1 Peach
to
1 Peach
3 Orange
4 Apple
6 Pear
2 Commenti
Risposta accettata
the cyclist
il 16 Giu 2017
Modificato: the cyclist
il 16 Giu 2017
C = {4, 'Apple';
3, 'Orange';
6, 'Pear';
1, 'Peach'};
sortrows(C)
ans =
4×2 cell array
[1] 'Peach'
[3] 'Orange'
[4] 'Apple'
[6] 'Pear'
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!