Sorting files with alphanumeric names in a structure array
显示 更早的评论
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?
回答(1 个)
Walter Roberson
2016-11-15
0 个投票
Look in the File Exchange; there are a couple of routines such as Natural Sort Filename, or Natural Sort
类别
在 帮助中心 和 File Exchange 中查找有关 Structured Data and XML Documents 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!