how to read mutliple text files

4 次查看(过去 30 天)
Raju Mandapti
Raju Mandapti 2011-7-3
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

回答(1 个)

Paulo Silva
Paulo Silva 2011-7-3
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

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by