Keeping track of order of rows when sorting a matrix
Ältere Kommentare anzeigen
I am trying to sort the matrix B below and also keep track of the order in which rows get swapped.
B = [100000001
010000100
001010010
010001100
001000010
000001100
100100000
001010000];
B = -sortrows(-B);
To keep track of each row number, can you for example add the row number column at the beginning, then sort the matrix according to all columns except the first? I am not sure how, because sortrows considers all columns. Or other than this is there any better method?
B = [1100000001
2010000100
3001010010
4010001100
5001000010
6000001100
7100100000
8001010000];
B = -sortrows(-B);
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!