필터 지우기
필터 지우기

fastest way to read in every m lines of a file sequentially?

조회 수: 1 (최근 30일)
Adam
Adam 2014년 11월 29일
편집: Azzi Abdelmalek 2014년 11월 29일
I need to read in every 100 lines of a very large file. Then I so some calculations with the data of those 100 lines then I get the next 100 lines (in order) and do the same set of calculations...and repeat until the last set of 1000 lines of the very large file. I cannot read in the entire large file at once, as it is too big.
What is the best (fastest) way to do this?
I already know the basic structure:
while(~feof(myfile))
a=fgetl(myfile)
end
Thanks!

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 29일
편집: Azzi Abdelmalek 2014년 11월 29일
fid=fopen(myfile)
k=0;
a=cell(1,100)
while ~feof(fid)
k=k+1
a{k}=fgetl(fid)
if mod(k,100)==0
%do your calculations
end
end
fclose(fid)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by