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

Home » Public Forums » archive » Re: Succinct way of testing array membership
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: Succinct way of testing array membership [message #81298 is a reply to message #81203] Thu, 30 August 2012 14:12 Go to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Thursday, August 30, 2012 7:09:35 PM UTC+2, Mike Galloy wrote:
> On 8/30/12 10:51 AM, godber wrote:
>
>> Is there a more succinct way of testing array membership than using where and n_elements on the indexes? Something like array_contains(a, 'pancakes')?
>
>>
>
>> Austin
>
>>
>
>
>
> In general, how about:
>
>
>
> print, where(a eq 'pancakes', /null) ? 'found' : 'not found'
>
>
>
> Mike
>
> --
>
> Michael Galloy
>
> www.michaelgalloy.com
>
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
>
> Research Mathematician
>
> Tech-X Corporation

Hi Mike,
I never noticed the presence of the /null keyword. Nice tip.
However, the version you provided will not work (at least not on my pc...).
How about:
print, (where(a EQ 'pancakes', /null) NE !NULL) ? 'found' : 'not found'
or
print, ((where(a EQ 'pancakes'))[0] GE 0) ? 'found' : 'not found'

Not as clean, but still doing the job.

Cheers,
Helder
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: A simple DLM question
Next Topic: plotting symbols on map using direct graphics 8.2

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

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

Total time taken to generate the page: 0.00366 seconds