How to sort a cell alphabetically?
Show older comments
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!
Accepted Answer
More Answers (1)
Aakash
on 23 Jun 2023
0 votes
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
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!