Sort cell array or char array in textual and numerical mode. Primary sort by first letter, secondary by second letter and so on. Numbers are considered an numerical values. The main interest in this function is that it can sort numbers with text, so string like 'a60' comes before 'a100'.
Designed specially for sorting files list.
Oren Yagev (2021). SORTN - sort textual lists (https://www.mathworks.com/matlabcentral/fileexchange/8399-sortn-sort-textual-lists), MATLAB Central File Exchange. Retrieved .
Relies on STR2NUM, which itself is a wrapper for EVAL, so has all of the disadvantages of string evaluation.
For more robust and versatile code that sorts alphanumerically, see my FEX submissions:
Boy, it took me a long time to find the bug in how I was doing it (which is very poor to begin with). This really solves the issue completely.
Note that Matthias's fix is essential though!
Very usefull - saved me a lot of time!
But there is a problem (Matlab 2008b, don't know about older releases) if a string contains the letter 'i' which is treated as a complex number and the program errors out at a later point. Therefore I added the following to line 141: "|| strcmp(tempString(i),'i')" what fixes the bug.
Saved me a lot of time.
Works as advertised! Good for sorting filenames rationally.
Worked as a charm
very nice program that sorts numbers with text and outputs a very useful index. great work.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!