Need help with Textread (Again)

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?

Respuestas (2)

Jiro Doke
Jiro Doke el 22 de En. de 2011

0 votos

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 el 22 de En. de 2011

0 votos

How would I convert those strings into numbers after? Is there a scientific type conversion?

4 comentarios

Paulo Silva
Paulo Silva el 22 de En. de 2011
MyNumber=str2num(MyString)
Walter Roberson
Walter Roberson el 22 de En. de 2011
What would it mean to convert "12337S006" in to a number? Do you just want the part before the S or M ? If so is it _certain_ to be exactly 5 digits before the S or M? Do you care if the S or M or following 3 digits are stored somewhere or can they be discarded?
Andrew
Andrew el 22 de En. de 2011
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 el 23 de En. de 2011
Why not use %f for those three fields?

Iniciar sesión para comentar.

Productos

Etiquetas

Preguntada:

el 22 de En. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by