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

Home » Public Forums » archive » subscripting arrays
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
subscripting arrays [message #46258] Sun, 13 November 2005 20:47 Go to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Hi all,

this is probably simple, but I can't figure it out right now:

I want to extract an element from a 2d array, and I have the 2d
subscripts of that element available as a 2-element vector.

IDL> a = dist(300)
IDL> b = [30, 50]
IDL> print, a[b]
30.0000 50.0000

Not what I want. What I want is

IDL> print, a[b[0], b[1]]
58.3095

Is there a more elegant way than splitting b up?

Thanks,
Benjamin
Re: subscripting arrays [message #46417 is a reply to message #46258] Tue, 22 November 2005 01:36 Go to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
Benjamin Hornberger wrote:
> Hi all,
>
> this is probably simple, but I can't figure it out right now:
>
> I want to extract an element from a 2d array, and I have the 2d
> subscripts of that element available as a 2-element vector.
>
> IDL> a = dist(300)
> IDL> b = [30, 50]
> IDL> print, a[b]
> 30.0000 50.0000
>
> Not what I want. What I want is
>
> IDL> print, a[b[0], b[1]]
> 58.3095
>
> Is there a more elegant way than splitting b up?
>
> Thanks,
> Benjamin

You can get the correct answer using the one-dimensional index.

a=dist(300)
b=[30,50]
scale=[1,300]
print, a[total(b*scale)]

but it's not very elegant.

Chris.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Best platform for IDL 6.2?
Next Topic: Re: SMOOTH function for 3D

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

Current Time: Wed Oct 08 13:49:17 PDT 2025

Total time taken to generate the page: 0.00475 seconds