Alphanumeric sorting of data

19 Ansichten (letzte 30 Tage)
Prathamesh Halagi
Prathamesh Halagi am 19 Jan. 2021
Hello,
I have data which is extracted from various excel fiels in a folder. I want to sort the data based on the data in the first column. The issue is the data in this column is for ex, '10000 Rest', '3200 Rest', '2000 Rest', etc.. I need the data to be in ascending form. The output I receive is '10000 Rest', '2000 Rest', '3200 Rest', etc. The required output for me is '2000 Rest', '3200 Rest', '10000 Rest'.. etc.
Is there a way to change the sorting type.
Thanks

Akzeptierte Antwort

Rishabh Mishra
Rishabh Mishra am 22 Jan. 2021
Bearbeitet: Rishabh Mishra am 22 Jan. 2021
Hi,
Based on my understanding of the issue, I suggest you to implement the 'sort_nat' function. The function is used to sort array of strings in natural alphabetcial order. I have added a reference example code below to demonstrate the use of sort_nat function.
arr = {'10000 Rest','3200 Rest','2000 Rest'};
sort_nat(arr);
Hope this helps!
  4 Kommentare
Walter Roberson
Walter Roberson am 25 Jan. 2021
Bearbeitet: Walter Roberson am 25 Jan. 2021
Can the alphabetic part always be ignored for sorting purposes? For example, no "2000 Checkpoint" along with "2000 Rest" ?
[~, idx] = sort(arrayfun(@(S) sscanf(S, '%d', 1), ds_2.Var1));
Prathamesh Halagi
Prathamesh Halagi am 25 Jan. 2021
Yes, I think it can be ignored as all data has number followed by REST.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices 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