How to sort a cell alphabetically?
66 ビュー (過去 30 日間)
古いコメントを表示
I want to sort a cell alphabetically, but when I using sort(), I got result as below:
A = ["AM";"AbnormalAccruals";"AOP";"AccrualsBM"];
sort(A)
However, the result I want is as follows:
"AbnormalAccruals"
"AccrualsBM"
"AM"
"AOP"
That is, the letter 'b' and 'c' should be arranged before the letter 'M'.
Thank you very much!
0 件のコメント
採用された回答
Parag Jhunjhunwala
2023 年 6 月 23 日
The following code sorts a cell alphabetically by converting all the strings to lowercase characters without affecting the original cell:
A = ["AM";"AbnormalAccruals";"AOP";"AccrualsBM"];
[~,idx]=sort(lower(A));
A=A(idx)
0 件のコメント
その他の回答 (1 件)
Aakash
2023 年 6 月 23 日
You can use the function provided in this matlab file exchange resource: https://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort?s_tid=srchtitle_sort%20strings_2
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!