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
  댓글 수: 1
Raju Mandapti
Raju Mandapti 2011년 7월 3일
hi Paulo Silva
thanks a lot...Its working nicely...

댓글을 달려면 로그인하십시오.

카테고리

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