How can I read the first 100 lines of a file?

조회 수: 13 (최근 30일)
tina26
tina26 2015년 4월 14일
댓글: tina26 2015년 4월 14일
Example of the file:
I am using this code to read the first line and it works fine. When I try to increase the size of A to 100 lines, instead of storing line by line is storing line by column. How to fix it? Regards, Tina
fid = fopen('NGRM_StrDisps_rot_03162015_short.txt');
formatSpec = '%f %f %f %f %f %f %f';
sizeA=[1 7];
A = fscanf(fid,formatSpec,sizeA);
fclose(fid)
  댓글 수: 1
tina26
tina26 2015년 4월 14일
I have a very large data file (.dat) around 60 gigs similar with the example I posted earlier. It is not necessary for me to import all of the data into MATLAB. I would like to read the first 5 lines and skip the sixth one to reduce the size of the file. After that I would like to read the first n lines (approximate 5 gigs of data) and save it under a different file. What is the easiest way to do that? Thank you.

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

채택된 답변

Jan
Jan 2015년 4월 14일
What about:
A = fscanf(fid, '%f', [7, inf])
Perhaps you want to transpose the output.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by