matlab order of picking files from folder

2 visualizaciones (últimos 30 días)
A
A el 1 de Jul. de 2011
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 comentario
Titus Edelhofer
Titus Edelhofer el 1 de Jul. de 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

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 1 de Jul. de 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.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by