MATLAB: Problem with sorting a structure

sortingstructures

I have a structure created by the dir command so I have something like that
images=dir('file*.tif')
The problem is that the struct created has its names that go like this
file1.tif
file10.tif
file2.tif
file20.tif
I want to sort all the contents of the struct so that it'll go like
file1.txt
file2.txt
file3.txt
...
file10.txt
But I want to do it without using cells. Just to sort the structure. Is there a way to do so?

Best Answer

images=dir('file*.tif');
n = {images.name}';
[~,ii] = sort(str2double(regexp(n,'(?<=file)\d*(?=\.txt)','match','once')));
images = images(ii);
Related Question