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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: shorten a vector [message #21625] Fri, 08 September 2000 08:33
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Martin Schultz wrote:
> Good. But why 0+ ???
> It works also for
> print, a[n<last:*]

Beats me. Why would I add zero to anything? Oh well.....

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
Re: shorten a vector [message #21627 is a reply to message #21625] Fri, 08 September 2000 02:04 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Liam Gumley wrote:
>
> 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 =
> 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

Good. But why 0+ ???
It works also for
print, a[n<last:*]

Martin


--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: shorten a vector
Next Topic: DISPLAY bug fixed

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

Current Time: Wed Oct 08 17:04:19 PDT 2025

Total time taken to generate the page: 0.00633 seconds