Sorting files with alphanumeric names in a structure array
Show older comments
Hi!
I'm trying to sort the text files of my struct array. The files are called:
Report (1).txt
Report (2).txt
.
.
.
Report (10).txt
Report (11).txt
.
.
.
Report (34).txt
What I want is something like:
Report (1).txt
Report (2).txt
Report (3).txt
Report (4).txt
.
.
.
Report (10).txt
But if I read directly without trying to sort them, this is the order in which they are read:
Report (1).txt
Report (10).txt
Report (11).txt
.
.
.
Report (2).txt
Report (20).txt
The amount of reports could be up to hundreds.
So, what I did to sort them is in the attached file.
However, for some reason it doesn't work properly and this is the output:
Report (1).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (2).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (3).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (4).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (5).TXT
Report (6).TXT
Report (6).TXT
Report (6).TXT
Report (6).TXT
Report (6).TXT
Report (6).TXT
Report (7).TXT
Report (8).TXT
Report (9).TXT
I'm getting crazy with this. I really don't find what I'm doing wrong. Could some of you please help me in this?
Answers (1)
Walter Roberson
on 15 Nov 2016
0 votes
Look in the File Exchange; there are a couple of routines such as Natural Sort Filename, or Natural Sort
1 Comment
LETICIA RUIZ
on 15 Nov 2016
Categories
Find more on Structured Data and XML Documents 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!