File Exchange

image thumbnail

SORTN - sort textual lists

version 1.0.0.0 (5.49 KB) by Oren Yagev
Sort text lists containing letters and numbers.

1 Download

Updated 31 Mar 2016

View License

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.

Cite As

Oren Yagev (2021). SORTN - sort textual lists (https://www.mathworks.com/matlabcentral/fileexchange/8399-sortn-sort-textual-lists), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

Stephen Cobeldick

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:

https://blogs.mathworks.com/pick/2014/12/05/natural-order-sorting/

https://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort

https://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-order-sort

Oren Shriki

thanks!

Eneko Unamuno

Ofir

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!
Toda Oren!

Matthias Klemm

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.

Fleur De Nil

Very usefull!!
Many thanks.

Frank Scharnowski

Many thanks!

Matt Sanders

Saved me a lot of time.

Scott Miller

Works as advertised! Good for sorting filenames rationally.

Roberto Fuentes

Worked as a charm

Perry Johnson

very nice program that sorts numbers with text and outputs a very useful index. great work.

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!