Import files from a folder into Matlab based on the files name

6 次查看(过去 30 天)
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.

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-5-26
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by