How can I skip lines when loading a text file?

조회 수: 64 (최근 30일)
Baba
Baba 2012년 2월 1일
댓글: Walter Roberson 2016년 11월 7일
Is there a way to use load to load a text file but skip a few lines which contain headers and other info and just load numerical data in columns that come after the headers?

답변 (1개)

Sven
Sven 2012년 2월 1일
Hi Baba, try importdata:
importdata(FILENAME, DELIM, NHEADERLINES) loads data from ASCII file FILENAME, reading numeric data starting from line NHEADERLINES+1.
  댓글 수: 5
Shania Hurst
Shania Hurst 2016년 11월 7일
편집: Shania Hurst 2016년 11월 7일
Using importdata with nheaderlines specified works for almost every file for me, but for some reason, I have one file that instead of skipping the first 20 lines as I want, instead imports ONLY the first 20 lines. I have no idea what would cause this to happen, does any one know of any circumstance in which this would happen? The file is a .txt file and has nearly 85k lines of data. The command I used is d = importdata('data.txt',' ',20);
Walter Roberson
Walter Roberson 2016년 11월 7일
Shania Hurst, I suggest you consider using readtable() with HeaderLines . (readtable() might even be able to figure out for itself how many header lines are there.)

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by