how to read list of files in correct sequence.

3 ビュー (過去 30 日間)
eanass abouzeid
eanass abouzeid 2016 年 7 月 15 日
コメント済み: Stephen23 2021 年 5 月 4 日
i have a folder containing files (images) named 1,2,....300, when i make filelist of the folder to use the files, matlab use the following sequance 1,10,101,..109,11,110....
how can i make the list in the correct file sequance .
Note: files are images used in image processing.
  5 件のコメント
Walter Roberson
Walter Roberson 2016 年 7 月 15 日
Do not pass it the directory information: pass it the file names extracted from the directory information. For example,
dinfo = dir('*.tif');
filenames = {dinfo.name};
sorted_filenames = sort_nat_file(filenames);
Stephen23
Stephen23 2021 年 5 月 4 日
Your could download my FEX submission natsortfiles, which was written to solve exactly this problem:
S = dir(..);
S = natsortfiles(S);

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

回答 (3 件)

Walter Roberson
Walter Roberson 2016 年 7 月 15 日
編集済み: Walter Roberson 2016 年 7 月 15 日

Image Analyst
Image Analyst 2016 年 7 月 15 日
See blog discussion of this "Pick of the week": http://blogs.mathworks.com/pick/2014/12/05/natural-order-sorting/

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 15 日
編集済み: Azzi Abdelmalek 2016 年 7 月 15 日
Your names look like this
s=arrayfun(@num2str,1:100,'un',0)
a=sort(s)
To sort them as you want
[~,ii]=sort(str2double(a))
out=a(ii)

カテゴリ

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