Re: appending to column [message #61371] |
Wed, 16 July 2008 09:30  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
R.G. Stockwell writes:
> <d.poreh@gmail.com> wrote in message
> news:c09c9b8a-35a7-41d7-9088-7bce01762053@x35g2000hsb.google groups.com...
> Folks
> I have a float array that first column is the integer part and second
> column is the decimal part of that number. How I can append this to
> column to get one column of that float number. For example:
>
> [123,456]------> 123.456
> ��� ���.
> Thanks
> Cheers
>
>
> Here is an example:
>
>
> IDL> print,a
> 0 1
> 2 3
> 4 311
> IDL> print,a[0,*] +
> float(a[1,*])/10^strlen(strcompress(string(a[1,*]),/rem))
> 0.100000
> 2.30000
> 4.31100
Alright, these explanations don't exactly leap to mind for me.
Which math class was I suppose to learn this in? :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
|
Re: appending to column [message #61375 is a reply to message #61374] |
Wed, 16 July 2008 09:17   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On Jul 16, 10:02 am, d.po...@gmail.com wrote:
> Folks
> I have a float array that first column is the integer part and second
> column is the decimal part of that number. How I can append this to
> column to get one column of that float number. For example:
>
> [123,456]------> 123.456
> ……… ……….
> Thanks
> Cheers
Like this?
IDL> d = long(1000 * randomu(seed, 2, 10))
IDL> print, d
895 528
34 183
877 169
614 604
205 789
537 526
413 360
643 687
360 881
512 874
IDL> print, d[0, *] + d[1, *] / (10. ^ (long(alog10(d[1, *])) + 1))
895.528
34.1830
877.169
614.604
205.789
537.526
413.360
643.687
360.881
512.874
Mike
--
www.michaelgalloy.cm
Tech-X Corporation
Software Developer II
|
|
|
Re: appending to column [message #61445 is a reply to message #61371] |
Wed, 16 July 2008 16:17  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"David Fanning" <news@dfanning.com> wrote in message
news:MPG.22e7d00f5c02361998a3f0@news.frii.com...
...
>> IDL> print,a
>> 0 1
>> 2 3
>> 4 311
>> IDL> print,a[0,*] +
>> float(a[1,*])/10^strlen(strcompress(string(a[1,*]),/rem))
>> 0.100000
>> 2.30000
>> 4.31100
>
> Alright, these explanations don't exactly leap to mind for me.
> Which math class was I suppose to learn this in? :-(
lol, sorry. I replied with a quick answer, then at the last second
changed the post to handle an arbitrary length of digits. For some
reason, counting the number digits jumped into my mind first, and
apparently I have found the least best algorithm for solving this
particular problem. Is there a prize for most obsfucated solution?
Cheers,
bob
PS changing a post at the last second is always a bad idea.
PPS 'least best' sounds better than 'worst', imho.
|
|
|
Re: appending to column [message #61461 is a reply to message #61371] |
Wed, 16 July 2008 10:20  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
>> IDL> print,a
>> 0 1
>> 2 3
>> 4 311
>> IDL> print,a[0,*] +
>> float(a[1,*])/10^strlen(strcompress(string(a[1,*]),/rem))
>> 0.100000
>> 2.30000
>> 4.31100
>
> Alright, these explanations don't exactly leap to mind for me.
> Which math class was I suppose to learn this in? :-(
>
> Cheers,
> David
division by 10, by 100 by 1000... hum.... too far back in time to
remember when we learn it! :)
1) get the number of digits for the decimal part
2) divide the decimals by 10 power to the number of digits( ->
10,100,1000 etc) so that 0 <= result < 1.0
3) add it to the integer part
Jean
|
|
|
Re: appending to column [message #61462 is a reply to message #61373] |
Wed, 16 July 2008 10:27  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
> IDL> print,a
> 0 1
> 2 3
> 4 311
> IDL> print,a[0,*] +
> float(a[1,*])/10^strlen(strcompress(string(a[1,*]),/rem))
> 0.100000
> 2.30000
> 4.31100
>
>
> Cheers,
> bob
While using strings, we can make it more efficiently. There is no need
to do any division, get the length or anything:
IDL> help, 1 + float('0.'+strtrim(234,2))
<Expression> FLOAT = 1.23400
Jean
|
|
|
Re: appending to column [message #61468 is a reply to message #61375] |
Wed, 16 July 2008 10:06  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
mgalloy@gmail.com writes:
> print, d[0, *] + d[1, *] / (10. ^ (long(alog10(d[1, *])) + 1))
Duh! Ok, nice. I've put this in my power user's toolkit now.
Could come in handy some day for a couple of other things. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: appending to column [message #61469 is a reply to message #61371] |
Wed, 16 July 2008 09:43  |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On Jul 16, 6:30 pm, David Fanning <n...@dfanning.com> wrote:
> R.G. Stockwell writes:
>> <d.po...@gmail.com> wrote in message
>> news:c09c9b8a-35a7-41d7-9088-7bce01762053@x35g2000hsb.google groups.com...
>> Folks
>> I have a float array that first column is the integer part and second
>> column is the decimal part of that number. How I can append this to
>> column to get one column of that float number. For example:
>
>> [123,456]------> 123.456
>> ……… ……….
>> Thanks
>> Cheers
>
>> Here is an example:
>
>> IDL> print,a
>> 0 1
>> 2 3
>> 4 311
>> IDL> print,a[0,*] +
>> float(a[1,*])/10^strlen(strcompress(string(a[1,*]),/rem))
>> 0.100000
>> 2.30000
>> 4.31100
>
> Alright, these explanations don't exactly leap to mind for me.
> Which math class was I suppose to learn this in? :-(
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
yes
thanks. I should also go more math class!:-)
Cheers
Dave
|
|
|