Import files from a folder into Matlab based on the files name
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Greetings. I face problem in extracting 400+ files from a folder into Matlab. Those files are labeled as: splash1, splash2, splash3....splash488 The code I use is:
a ='C:\Users\Ace\Desktop\reTest\';
A =dir( fullfile(a, '*.bmp') );
fileNames = { A.name };
The problem comes when I realise the 'fileNames' array contains elements which are labeled as: splash1, splash10, splash100, splash101, splash102... like in a binary sequence.
I need the Matlab to extract the files from the folder as: splash1, splash2, splash3, ....splash488
Maybe I have missed out a clue or a more specific or accurate function. Any help, comment is welcomed! Thanks.
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 26 Mai 2011
So you want to sort your file names according to the value of the numeric part of the file name. This should work.
filenames={'sp1','sp10','sp2','sp20','sp3','sp30'};
a=regexp(filenames,'\d+','match');
b=[a{:}];
c=cellfun(@str2num,b);
[d,index]=sort(c);
NewFilenames=filenames(index)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!