필터 지우기
필터 지우기

How can I extract data from a large ASCII file?

조회 수: 2 (최근 30일)
anton fernando
anton fernando 2014년 5월 20일
편집: Cedric 2014년 5월 20일
I have a ASCII data file with unknown number of columns and rows. In the file there are some unwanted text lines on top. I want to read only some of the columns in the data set with the header by removing the text lines on top. I appreciate if anyone can help.

채택된 답변

Cedric
Cedric 2014년 5월 20일
>> doc textscan
and use the parameter HeaderLines to skip the header. Supposing that you have 7 header lines and that you need columns 1 and 3 (discarding the rest of each line), you should have something like:
content = fileread( 'myData.txt' ) ;
data = textscan( content, '%f%*f%f%*[^\n]', 'HeaderLines', 7, ...
'CollectOutput', true ) ;
data = data{1} ;
where you see a * in the formatSpec argument to skip column 2 and %*[^\n] at the end to skip the rest of the line.
  댓글 수: 14
anton fernando
anton fernando 2014년 5월 20일
Thank you. I really appreciate your help.
Cedric
Cedric 2014년 5월 20일
My pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by