matlab order of picking files from folder
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Titus Edelhofer
le 1 Juil 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
Réponses (1)
Jan
le 1 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!