Re: what is the highest subscript in the array?!? [message #70768] |
Thu, 06 May 2010 21:27  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 5/6/10 9:32 pm, Craig Markwardt wrote:
> On May 6, 10:26 pm, Michael Galloy<mgal...@gmail.com> wrote:
>> munka<mynameismu...@gmail.com> wrote:
>>> Hello team,
>>
>>> I find myself wanting to use the highest subscript in an array and
>>> coding "flux[n_elements(flux)-1]"... I seem to remember seeing a
>>> shortcut on here, and I can't remember what it is.
>>
>> You are stuck using that until IDL 8.0 comes out, then you can use -1.
>
> Really? First of all a[-1] used to be an error and now it won't be.
> That could be dangerous change of expectations.
>
> Craig
It does not change valid existing behavoir:
IDL> print, a[[-1]]
0.00000
It would just change conditions which would have caused errors before.
So code that caught the out-of-bounds runtime error instead of just
checking the index will break.
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
|
|
Re: what is the highest subscript in the array?!? [message #70770 is a reply to message #70769] |
Thu, 06 May 2010 21:21   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 5/6/10 8:44 pm, munka wrote:
> On May 6, 9:26 pm, Michael Galloy<mgal...@gmail.com> wrote:
>> munka<mynameismu...@gmail.com> wrote:
>>> Hello team,
>>
>>> I find myself wanting to use the highest subscript in an array and
>>> coding "flux[n_elements(flux)-1]"... I seem to remember seeing a
>>> shortcut on here, and I can't remember what it is.
>>
>> You are stuck using that until IDL 8.0 comes out, then you can use -1.
>>
>> Mike
>> --www.michaelgalloy.com
>> Research Mathematician
>> Tech-X Corporation
>
> :(
> -1 doesn't even work.
>
> Also, clicking on your signature link brings me to "http://
> www.google.com/www.michaelgalloy.com" :\
You need IDL 8.0:
IDL> a = findgen(10)
IDL> print, a[-1]
9.00000
IDL> print, a[-2]
8.00000
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
|
|
|
|
Re: what is the highest subscript in the array?!? [message #70866 is a reply to message #70772] |
Thu, 06 May 2010 21:30  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 5/6/10 8:44 pm, munka wrote:
[snipped]
> Also, clicking on your signature link brings me to "http://
> www.google.com/www.michaelgalloy.com" :\
Not sure what Google is doing there; it works fine in my newsreader, but
Google Groups is doing something funky.
Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
|
|
|
|