Alphanumeric sorting of data
5 ビュー (過去 30 日間)
古いコメントを表示
Prathamesh Halagi
2021 年 1 月 19 日
コメント済み: Prathamesh Halagi
2021 年 1 月 25 日
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
採用された回答
Rishabh Mishra
2021 年 1 月 22 日
編集済み: Rishabh Mishra
2021 年 1 月 22 日
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 件のコメント
Walter Roberson
2021 年 1 月 25 日
編集済み: Walter Roberson
2021 年 1 月 25 日
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));
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!