how to read list of files in correct sequence.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
2021년 5월 4일
Your could download my FEX submission natsortfiles, which was written to solve exactly this problem:
S = dir(..);
S = natsortfiles(S);
답변 (3개)
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/
댓글 수: 0
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!