matlab order of picking files from folder
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i am picking files from folder having more than 15K files and files are named as 1,2,3.....in sequential order. When I execute below code, I find files are selected at random and no sequential order is maintained. Any way to do it.
folder_content = dir ([my_folder,'*',file_ext]); num_files = size (folder_content,1);
for i=1:num_files string = [my_folder,folder_content(i,1).name]; [fpath fname fext]=fileparts(string); disp(fname); end
1 Kommentar
Titus Edelhofer
am 1 Jul. 2011
Hi,
I'm not exactly sure what the problem is? You could use sort on {folder_content.name}. The dir does not allow for specifying how the files are sorted ...
Titus
Antworten (1)
Jan
am 1 Jul. 2011
Although this is not guaranteed, the reply of DIR is usually sorted alphabetically - at least I have not ssen any counter-example yet. Which OS are you using to get an randomly sorted result?
But the alphabetical sorting might differ from your expectations:
sort({'1', '2', '3', '10', '11', '20'})
>> '1' '10' '11' '2' '20' '3'
Do you want something else? Then use SSCANF to convert the strings to a number, and the 2nd output of SORT to get the sorting index in "natural" order.
0 Kommentare
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!