How to sort a cell alphabetically?
67 次查看(过去 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!