Rearranging text file order
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys. I have a text file that has a few rows and columns: Name WIN LOSE
I have a few data of names, win, and lose sorted.
I'm having difficulties figuring out a way to rearrange the text file data from higher to lower win score while bringing the particular lose and name row specifics along .. how do i do this ? Please help me out :S
0 commentaires
Réponses (2)
Michael Haderlein
le 17 Oct 2014
I'm not 100% sure if I understood your question correctly, but this might be what you need:
>> name={'A';'B';'C'};
>> score=[3;1;2];
>> [sort_score,ind]=sort(score);
>> sort_name=name(ind);
>> sort_score
sort_score =
1
2
3
>> sort_name
sort_name =
'B'
'C'
'A'
0 commentaires
Guillaume
le 17 Oct 2014
Modifié(e) : Guillaume
le 17 Oct 2014
You're not telling us how you're storing the content on your text file, so I'm assuming a cell array. In any case, to sort data according to a column and bring along the others, use sortrows:
scores = {'Player 1', 5, 3
'Player 2', 4, 9
'Player 3', 7, 1};
sortrows(scores, 2)
>> ans =
'Player 2' [4] [9]
'Player 1' [5] [3]
'Player 3' [7] [1]
0 commentaires
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!