how to read mutliple text files
4 views (last 30 days)
Show older comments
hi i am very new to matlab. i wanted to read multiple text files. who files names have increment in number such data1112, data1113... 4096 files..
i have single text file read program...
filename='data1112.txt' fid=fopen(filename, 'r') tline=fgetl(fid) [a,b]=strtok(tline, '=') [c,d]=strtok(b, '=') cnum=str2num(c) fclose(fid)
Pls mention how to use for loop and i wanted to extract all data in one matrix form..
Thanks in advanced
0 Comments
Answers (1)
Paulo Silva
on 3 Jul 2011
data=cell(4096-1112,1);
for n=1112:4096
filename=['data' num2str(n) '.txt']
%insert the code to get data from the file
a=rand;b=rand; %this is my fake data
c=rand;d=rand; %more fake data
data{n-1111}={a,b,c,d}; %each cell is the data for each file
%I have no idea about the size or type of a,b,c,d so I used cells again
end
See Also
Categories
Find more on Text Data Preparation 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!