- generate the names using sprintf (as shown on the page madhan ravi linked to), or
- use dir to get the actual filenames, and then sort them. The simplest way to do this is to download my FEX submission natsortfiles, and use it like this:
how to read txt files in the same folder
3 ビュー (過去 30 日間)
古いコメントを表示
I have text files in a folder. Their names are
BC_1.txt, BC_2.txt, BC_3.txt, ..., BC_100.txt.
I would like to know how to read all files with a loop. Thank you so much.
1 件のコメント
Stephen23
2018 年 12 月 31 日
If you want to read the files in alpha-numeric order then you can either:
S = dir('BC*.txt');
C = natsortfiles({S.name});
for k = 1:numel(C)
F = C{k}
... do whatever with filename F
end
採用された回答
KSSV
2018 年 12 月 31 日
txtfiles = dir('*.txt') ;
N = length(txtfiles) ;
for i = 1:N
thisfile = txtfiles(i).name ;
% do waht you want
end
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
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!