Using FGETL to skip 2 header lines

How do I use FGETL to skip 2 header lines?
My data file looks like this
Row 1: ID FName LName Year Class
Row 2: ---------------------------------
Row 3: data starts here
After I open the file with FOPEN
fid=fopen('textfile.dat','r');
How do I use FGETL to skip the 2 header lines (rows 1 & 2)?
Thanks in advance.

 채택된 답변

per isakson
per isakson 2013년 7월 24일

0 개 추천

Call it twice and ignore the results.

댓글 수: 5

Thanks for your reply. How do I call it twice? (sorry, newbie here. Only 2nd week into my matlab class.)
fid=fopen('textfile.dat','r');
line=fgetl(fid);
Cedric
Cedric 2013년 7월 24일
편집: Cedric 2013년 7월 24일
fid=fopen('textfile.dat','r');
fgetl(fid); % Read/discard 1 line.
fgetl(fid); % Read/discard 1 line.
% Then you start reading and processing lines.
ERC
ERC 2013년 7월 24일
Thank you!
Cedric
Cedric 2013년 7월 24일
Don't forget to [ Accept the Answer ] if it solved your problem.
ERC
ERC 2013년 7월 24일
Done. Thanks for the reminder.

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

추가 답변 (1개)

Dan Seal
Dan Seal 2013년 7월 27일

0 개 추천

A good way to read data from text files with headers is with the textscan function. When calling textscan, you an specify a number of header rows in your file. For example, if ID and Year are numeric and the other columns are strings, use:
fid=fopen('textfile.dat','r');
C = textscan(fid, '%d %s %s %d %s', 'HeaderLines', 2);

카테고리

제품

태그

질문:

ERC
2013년 7월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by