views:

72

answers:

1

I have 500 files .TXT, for example:

abc-1.TXT  
adfer-2.txt  
affd-3.TXT  
asxdcccc-4.TXT  
... 

How can I change the following program to achieve results in order of numbers in the filenames:

Names = dir('MyFile\*.TXT');  
for i = 1:500  
    fn = strcat(['MyFile\' Names(i).name]);  
    ...  

is there a way to make the loop on the numbers contained in the file names?
the problem with the above program is that I got results that do not follow the order of the numbers contained in the file names.

THANK YOU to everyone who helped me to advance in my work.

+1  A: 
names={'abc-1.TXT';
'affd-3.TXT';
'sdfg-33.txt';
'adfer-2.txt';
'asxdcccc-4.TXT'};

for i=1:length(names)
    [v1 v2]=regexp(names{i},'[1-9]*');
    numbers(i)=str2num(names{i}(v1:v2));
end

[B,IX] = sort(numbers);
names{IX}

The last line will print the names in the order of numbers. I guess you can carry on from here.

Oh, and you should start with

Names = dir('*.TXT');
names = Names.name;
AVB
The last line should be: names = {Names.name}'; Anyway good answer.
yuk

related questions