MATLAB: Sorting files inside a folder

alphanumeric sortnatsortnatsortfilessorting files in an order

I have files named
1 1a.bmp
1 1b.bmp
1 2a.bmp
1 2b.bmp
...
2 1a.bmp
2 1b.bmp
2 2a.bmp
2 2b.bmp
....
23 1a.bmp
23 1b. bmp
and so on
in a single folder. I have to sort these files in the order
1 1a.bmp
1 1b.bmp
2 1a.bmp
2 1b.bmp
3 1a.bmp
3 1b.bmp
...
23 1a.bmp
23 1b.bmp
1 2a.bmp
1 2b.bmp
....
23 2a.bmp
23 2b.bmp
and so on. Kindly help me with the syntax for this in Matlab.

Best Answer

This code gives the order requested in the original question:
C = {...
'1 1a.bmp';...
'1 1b.bmp';...
'1 2a.bmp';...
'1 2b.bmp';...
'2 1a.bmp';...
'2 1b.bmp';...
'2 2a.bmp';...
'2 2b.bmp';...
'23 1a.bmp';...
'23 1b.bmp';...
};
%
fun = @(s)sscanf(s,'%u%u%c.bmp').';
D = cellfun(fun,C,'UniformOutput',false);
[~,idx] = sortrows(cell2mat(D),[2,1,3]);
out = C(idx)
generating this:
out =
'1 1a.bmp'
'1 1b.bmp'
'2 1a.bmp'
'2 1b.bmp'
'23 1a.bmp'
'23 1b.bmp'
'1 2a.bmp'
'1 2b.bmp'
'2 2a.bmp'
'2 2b.bmp'