how to read mutliple text files
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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 Center 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!