Creating a loop in order to read .txt files
12 views (last 30 days)
Show older comments
Ivan Mich
on 26 Sep 2019
Commented: KALYAN ACHARJYA
on 26 Sep 2019
Hello,
I have files like these: A_ac_s001.txt , A_ac_s002.txt, A_ac_s003.txt ,..., A_ac_s100.txt
I would like to create a loop which will read 'one to one' each file. Does anyone knows which command should I use?
0 Comments
Accepted Answer
KALYAN ACHARJYA
on 26 Sep 2019
list=dir('*.txt');
for j=1:length(list)
file_text=textread(list(j).name);
%.....code
end
6 Comments
Stephen23
on 26 Sep 2019
"I meant that finally i would like to create 2 loops..."
So create two loops:
S = dir('A_ac*.txt');
for k = 1:numel(S)
S(k).name
end
S = dir('A_bb*.txt');
for k = 1:numel(S)
S(k).name
end
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!