필터 지우기
필터 지우기

Need help with Textread (Again)

조회 수: 1 (최근 30일)
Andrew
Andrew 2011년 1월 22일
Trying to read in the following file:
Id DOMES# Location lat(decimal_degrees_-90to90) long(-180to180) height(metres)
---- --------- ----------------------- --- ---- ----------------------------------
1181 14106S001 Potsdam 5.2380263e+001 1.3065290e+001 1.4784603e+002
1824 12356S001 Golosiiv 5.0363130e+001 3.0495881e+001 2.1241848e+002
1831 12368S001 Lviv 4.9917567e+001 2.3954413e+001 3.5918362e+002
1863 12340S001 Maidanak-2 3.8685738e+001 6.6943090e+001 2.7138656e+003
1864 12340S002 Maidanak-1 3.8684895e+001 6.6943086e+001 2.7135990e+003
1868 12341S001 Komsomolsk-na-Amure 5.0694613e+001 1.3674383e+002 2.6940265e+002
1870 12309S001 Mendeleevo 5.6027584e+001 3.7223454e+001 2.5618141e+002
1873 12337S003 Simeiz 4.4413187e+001 3.3990950e+001 3.6458796e+002
1884 12302S002 Riga 5.6948551e+001 2.4059074e+001 3.1332111e+001
1885 12302S006 Riga 5.6948721e+001 2.4058627e+001 3.0968508e+001
1893 12337S006 Katsively 4.4393173e+001 3.3970123e+001 6.8144159e+001
1953 40701S001 Santiago_de_Cuba 2.0011941e+001 -7.5762220e+001 1.7767477e+001
7035 40436M003 Otay 3.2600682e+001 -1.1684085e+002 9.8867137e+002
7046 40438M002 Bear_Lake 4.1933542e+001 -1.1142071e+002 1.9632293e+003
I've tried to use this function:
[ID,Domes,Location,lat,long,height] = textread('slr_sites.dat','%d%d%s%s%s%s','headerlines',2,'whitespace',' \b\t\n\r');
I keep getting the error: ??? Error using ==> dataread Trouble reading integer from file (row 2, field 2) ==> .4784603e+002\n
Can anyone fix this?

답변 (2개)

Jiro Doke
Jiro Doke 2011년 1월 22일
Your second column cannot be stored as integers. There's a letter "S" or "M" in it. This should work (note the format string):
[ID,Domes,Location,lat,long,height] = textread('slr_sites.dat', '%d%s%s%s%s%s', 'headerlines', 2, 'whitespace', ' \b\t\n\r');

Andrew
Andrew 2011년 1월 22일
How would I convert those strings into numbers after? Is there a scientific type conversion?
  댓글 수: 4
Andrew
Andrew 2011년 1월 22일
I was talking about the lat/long/h values. I would want to change them to the numbers with the exponent added on. Sorry about not being clear.
Walter Roberson
Walter Roberson 2011년 1월 23일
Why not use %f for those three fields?

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by