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

Home » Public Forums » archive » Check if coordinate is in array
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: Check if coordinate is in array [message #34217 is a reply to message #34072] Thu, 20 February 2003 06:36 Go to previous message
Chris[1] is currently offline  Chris[1]
Messages: 23
Registered: January 2003
Junior Member
"Thomas Gutzler" <tgutzler@ee.uwa.edu.au> wrote in message
news:3E544CAB.6020006@ee.uwa.edu.au...
> Hi again.
>
> Here is the daily riddle:
> Is there a faster way to check, if a coordinate (2-element array) is
> element of an array of coordinates (2,n-element array) than this:
>
> FUNCTION is_element_of_2D, x, arr
> xidx = WHERE(arr[0,*] EQ x[0], c1)
> yidx = WHERE(arr[1,*] EQ x[1], c2)
> IF (c1 + c2 GT 0) THEN tmp = WHERE(MATRIX_MULTIPLY(xidx, $
> 1./TRANSPOSE(yidx)) EQ 1, c3) ELSE c3 = 0
> RETURN, c3 NE 0
> END
>

Wouldn't it be faster to do the following:

;; initialize the return value
c2 = 0
;; find the matching first coordinates
xidx = where(arr[0,*] eq x[0],c1)
;;search only among coordinates where the first matches
if c1 gt 0 then yidx = where(arr[1,xidx] eq x[1],c2)
return, c2 gt 0

Note also that it is possible that an element of your yidx might be zero,
which is going to cause you some problems.
Chris
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Is there a way to use C++ code in IDL
Next Topic: Sort an Array of Structures...

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

Current Time: Wed Oct 15 09:46:15 PDT 2025

Total time taken to generate the page: 6.98630 seconds