comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: appending to column
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: appending to column [message #61371] Wed, 16 July 2008 09:30 Go to next message
David Fanning is currently offline  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 #61373 is a reply to message #61371] Wed, 16 July 2008 09:20 Go to previous messageGo to next message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
<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


Cheers,
bob
Re: appending to column [message #61374 is a reply to message #61373] Wed, 16 July 2008 09:18 Go to previous messageGo to next message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Jul 16, 5:02 pm, 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

Well, assuming you have the same number of significant figures in each
element:

Values = Array[0,*] + Array[1,*]/1000.0

Regards,
Chris
Re: appending to column [message #61375 is a reply to message #61374] Wed, 16 July 2008 09:17 Go to previous messageGo to next message
Michael Galloy is currently offline  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 Go to previous message
R.G. Stockwell is currently offline  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 Go to previous message
Jean H. is currently offline  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 Go to previous message
Jean H. is currently offline  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 Go to previous message
David Fanning is currently offline  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 Go to previous message
d.poreh is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: 330 Humingbird GPS 33020
Next Topic: Re: IDL Matrix Multiply and Dual-Core CPUs

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:31:51 PDT 2025

Total time taken to generate the page: 0.00661 seconds