How to nat sort rows of a struct
Show older comments
Hi,
I have a matlab script that I am developing for analysing data. After completing some testing last week I have come into the same issue as many others that when I have listed my files that have not been in numerical order. Currently, my files are in this order:

However I need to reorder the rows to have them listed in numerical order with the contents of the rows staying together:
'Emission_1.txt'
'Emission_2.txt'
'Emission_3.txt'
'Emission_4.txt'
'Emission_5.txt'
'Emission_6.txt'
'Emission_7.txt'
'Emission_8.txt'
'Emission_9.txt'
'Emission_10.txt'
'Emission_11.txt'
'Emission_12.txt'
The output struct that I get at the moment looks like
I am really struggling to get them into the correct order while keeping the struct in the same layout. I would really prefer to does as the rest of my script is now built up and I would prefer not to have to change it.
I have looked into using things like natsort, sort_nat and nestedSortStruct but I can't seem to get the output that I need.
Is there a way that this can be done?
I will put my code with attachments too to try and help
1 Comment
"I am really struggling to get them into the correct order..."
Download my FEX submission natsortfiles, unzip it onto the search path, and then simply use it like this:
S = dir(..);
S = natsortfiles(S);
... your code
Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays 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!