how to read text file and to ignore the first 10 rows and to take only the 4rth and 5th columns?

조회 수: 3 (최근 30일)
how to read text file and to ignore the first 10 rows and to take only the 4rth and 5th columns? from this file: http://iopscience.iop.org/0266-5611/17/6/301/media/dielTM_dec4f.exp
i tried to use textscan but i don't really understand how to and it looks a bit complicated
any other solution or how to do this?

채택된 답변

per isakson
per isakson 2014년 9월 15일
편집: per isakson 2014년 9월 15일
Try
cac = textscan( fid, '%*f%*f%*f%f%f%*f%*f', 'Headerlines', 10 );
Doc says: &nbsp %* &nbsp Skip the field. textscan does not create an output cell for any field that it skips.
That's not too complicated!
&nbsp
"any other solution or how to do this?" &nbsp None less complicated than textscan - AFAIK
  댓글 수: 1
Image Analyst
Image Analyst 2014년 9월 15일
dlmread() would be easier if it only had a headerlines option. With textscan() you also have to call fopen() and fclose().

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 9월 15일
Maybe try importdata()
delimiterIn = ' ';
headerlinesIn = 10;
myStructure = importdata(filename,delimiterIn,headerlinesIn);
data = myStructure.data;
Worked for me.
  댓글 수: 2
Image Analyst
Image Analyst 2014년 9월 15일
You could do it all in just 2 lines instead of the 3 required for textscan(). Plus you don't need to figure out all that stuff about '%*f%*f%*f%f%f%*f%*f' since it figures it out for you.
per isakson
per isakson 2014년 9월 16일
편집: per isakson 2014년 9월 16일
Problem is I don't know about importdata ;-).

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

카테고리

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