matlab order of picking files from folder

2 ビュー (過去 30 日間)
A
A 2011 年 7 月 1 日
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 件のコメント
Titus Edelhofer
Titus Edelhofer 2011 年 7 月 1 日
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

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2011 年 7 月 1 日
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.

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by