Re: newbie question
- To: mathgroup at smc.vnet.net
- Subject: [mg93238] Re: newbie question
- From: Peter Breitfeld <phbrf at t-online.de>
- Date: Sat, 1 Nov 2008 05:05:20 -0500 (EST)
- References: <geee9l$ac9$1@smc.vnet.net>
polymedes schrieb:
> Hi I'm trying to apply the function ToDegrees (from Geodesy package)
> to an array of data. It does not seem to work on arrays. Can somebody
> give me an idea on how to do this conversion? Ideally, I'd like to
> import a file in the following format:
>
> 12,23,49 70,45,30
> 12,25,41 70,46,40
> 12,26,51 70,47,50
> 12,27,55 70,48,33
> .
> .
> .
>
>
> How can I convert the above numbers (from the given format, i.e.
> degrees-minutes-seconds) to decimal numbers?
>
I pasted your example data into a file data.txt. The I did the
following:
(raw=ReadList["data.txt",Word,WordSeparators->{" ","\n",","}])//InputForm
Out={"12", "23", "49", "70", "45", "30", "12", "25", "41", "70", "46", \
"40", "12", "26", "51", "70", "47", "50", "12", "27", "55", "70", \
"48", "33"}
You see, the Elements of the list raw are String. This may not be the
case for you, if your file was created in another way. Now I group
the data into tuples of three:
blocks=Partition[ToExpression /@ raw,3]
Out={{12, 23, 49}, {70, 45, 30}, {12, 25, 41}, {70, 46, 40},
{12, 26, 51}, {70, 47, 50}, {12, 27, 55}, {70, 48, 33}}
You must not use ToExpression/@, if your raw list elements aren't strings.
Then I feed the blocks to ToDegree:
ToDegree/@blocks //N
Out={12.3969, 70.7583, 12.4281, 70.7778, 12.4475, 70.7972, 12.4653, 70.8092}
Gruss Peter
--
==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de