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 #69669 is a reply to message #35914] Thu, 04 February 2010 02:22 Go to previous messageGo to previous message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Thu, 4 Feb 2010 01:27:26 -0800 (PST), Dave_Poreh
<d.poreh@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)
[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: Fri Oct 10 02:09:00 PDT 2025

Total time taken to generate the page: 0.23379 seconds