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

Home » Public Forums » archive » Re: last array index subscript
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: last array index subscript [message #33732 is a reply to message #33731] Thu, 23 January 2003 10:40 Go to previous messageGo to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Chad Bender wrote:
>
> Hi --
>
> Is there a way in IDL to directly reference the last element of a vector
> without first determining how many elements the vector contains?
>
> For example, something like:
>
> n=N_Elements(my_array)
> value=my_array[n-1]
>
> except without having to make the call to N_Elements. Granted, avoiding
> the N_Elements call probably doesn't save a lot of time. But I figured
> that with all of the complicated syntax that IDL accepts, there might be a
> direct way to do this. The Bldg Apps guide says you can extract a
> subarray from some element e to the end of the array like this:
>
> subarray=my_array[e:*]
>
> So it seems to me that IDL knows what that last index is. I tried
> something like:
>
> value=my_array[*-1], but (not unexpectedly) this caused a syntax error.
>
> I figure that what I want is probably impossible, but if anyone knows how
> to do it your advice is appreciated.

This doesn't have any advantages that I can see over the N_ELEMENTS
method; in fact, it's quite a bit less efficient; but it does work:

(reverse(my_array))[0]
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Cropping of IDLgrVolume?
Next Topic: Re: formatting array output?

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

Current Time: Fri Oct 10 05:04:52 PDT 2025

Total time taken to generate the page: 0.32153 seconds