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

Home » Public Forums » archive » Re: shorten a vector
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: shorten a vector [message #21629 is a reply to message #21627] Thu, 07 September 2000 19:30 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Andrew <noymer@my-deja.com> wrote in message
news:8p9gie$6m5$1@nnrp1.deja.com...
> What's the easiest way to shorten an array by n units
> by chopping off the first n elements of the array.
>
> E.G: I want to make [ 4 6 7 20 15 ]
>
> Into [ 6 7 20 15]. Here n=1.

a = [4, 6, 7, 20, 15]
n = 1
print, a[(0 + n):*]
6 7 20 15

To make it more general, use n_elements to get the index of the last
element:

last = n_elements(a) - 1
n = 1
print, a[(0 + (n < last)):*]
6 7 20 15
n = 4
print, a[(0 + (n < last)):*]
15
n = 10
print, a[(0 + (n < last)):*]
15

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: shorten a vector
Next Topic: DISPLAY bug fixed

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

Current Time: Fri Oct 10 14:19:14 PDT 2025

Total time taken to generate the page: 0.00325 seconds