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

Home » Public Forums » archive » WHERE problems (longish)
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: Where problem [message #69617 is a reply to message #35914] Thu, 04 February 2010 02:30 Go to previous messageGo to previous message
d.poreh is currently offline  d.poreh
Messages: 406
Registered: October 2007
Senior Member
On Feb 4, 2:22 am, Wox <s...@nomail.com> wrote:
> On Thu, 4 Feb 2010 01:27:26 -0800 (PST), Dave_Poreh
>
> <d.po...@gmail.com> wrote:
>> Folks
>> I can’t solve this problem. Will somebody tells me what is going on?
>> x=findgen(100)
>> y=[30,40,50,80]*1.0
>> index=where(x eq y)
>> but every time gives me:
>>> index=-1
>> Any help highly appreciated
>> Cheers
>> Dave
>
> Two issues:
>
> 1. wrong use of where:
>
> IDL> x=findgen(100)
> IDL> y=[30,40,50,80]
> IDL> b=x eq y
>
> b will have 4 elements (smallest of the x and y dimension) and will
> b[i] will only be 1 when x[i] eq y[i]. So this is not what you want.
>
> What you can do is:
> ind=value_locate(x,y)
> ind2=where(x[ind] ne y,ct)
> if ct ne 0 then ind[ind2]=-1
>
> 2. comparing floating point numbers, see:www.dfanning.com/code_tips/comparearray.html
>
> IDL> x=findgen(100)
> IDL> y=[30,40,50,80]*1.0
>
> I would do something like
>
> small=1e-6
> ind=value_locate(x,y)
> ind2=where(abs(x[ind] - y) gt small,ct)
> if ct ne 0 then begin
>     ind[ind2]++
>     ind2=where(abs(x[ind] - y) gt small,ct)
>     if ct ne 0 then ind[ind2]=-1
> endif
>
> See David's page on what "small" should be.
>
> You could also do something like this
>
> x=rebin(x,n_elements(x),n_elements(y),/sample)
> y=rebin(transpose(y),n_elements(x),n_elements(y),/sample)
> ind=where(abs(x - y) gt small, ct)
> ... and so on ... which is ok for small arrays but not for large
> arrays (memory issues)

Thanks Guys. This is exactly what I want.
Cheers
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: questions onn symbol and fonts
Next Topic: File Delete -- Friggin A!!

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

Current Time: Wed Oct 08 17:47:17 PDT 2025

Total time taken to generate the page: 0.00396 seconds