file list when "dir" to import data
이전 댓글 표시
I am using "dir" to import .txt filedata. Here is the simple code that I used.
liste = dir('*.txt');
My text files has number in the name. The problem is that dir read the file that has "10" ahead of "2". The file names in the "liste" are listed as follows.

How can I make the "liste" to have the sequentially increasing number in the name?
*1.txt, *2.txt,*3.txt,...
Thanks in advance.
댓글 수: 1
Mathieu NOE
2022년 6월 29일
hello
the solution is here :
채택된 답변
추가 답변 (1개)
Image Analyst
2022년 6월 29일
It's best if you can just add leading zeros when you create the files, like
baseFileName = sprintf('blah blah blah fubar-ROI%3.3d.TXT', yourNumber);
The %3.3d will make sure numbers appear as 001, 002, .... 010, 011, ......200, ..... 999 etc.
If your max number is bigger than 3 digits then use 4.4 or 5.5 or whatever.
Otherwise see
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!