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

Home » Public Forums » archive » Inverting indices?
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
Inverting indices? [message #2353] Wed, 29 June 1994 09:23 Go to next message
kkobayas is currently offline  kkobayas
Messages: 7
Registered: June 1994
Junior Member
Hi,

I guess I didn't say it right in the subject, but what I want to do
is, say, for i=[1,3,5] as indeces for a 10-element array, I need to find
the indeces for points NOT set by i, that is, j=[0,2,4,6,7,8,9].

Am I making sense? I just need to do j=OPPOSITE(i,10) so that when
i=[1,3,5] it'll return j=[0,2,4,6,7,8,9].

I couldn't find a built-in routine that does this. I tried the following
code:

FUNCTION opposite,idx,n
k = bytarr(n)
k(idx)=1
return,where(not k)
end

but this didn't seem to work for some reason. The shortest working
routine I could come up with is:

FUNCTION opposite,index,n
k = bytarr(n)
k(*)=1
k(index)=0
return,where(k)
end

I somehow feel there must be a more efficient way of doing this. Can
anyone suggest a better solution? Also, why doesn't the first routine work?





--
------------------------------------------------------------ -----------------
| "Would you tell me, please, which way I
Ken Kobayashi | ought to go from here?"
| "That depends a good deal on where you
kkobayas@husc.harvard.edu | want to get to." - Lewis Carroll
Re: Inverting indices? [message #2448 is a reply to message #2353] Wed, 29 June 1994 13:26 Go to previous messageGo to next message
robijn is currently offline  robijn
Messages: 18
Registered: June 1994
Junior Member
In article <kkobayas.772907009@husc9.harvard.edu>,
Ken Kobayashi <kkobayas@husc9.harvard.edu> wrote:
>
> Am I making sense? I just need to do j=OPPOSITE(i,10) so that when
> i=[1,3,5] it'll return j=[0,2,4,6,7,8,9].
>
> I couldn't find a built-in routine that does this. I tried the following
> code:
>
> FUNCTION opposite,idx,n
> k = bytarr(n)
> k(idx)=1
> return,where(not k)
> end
>
> but this didn't seem to work for some reason.

A 'false' value in IDL is -1, not 1. So change k(idx)=1 to k(idx)=-1 and
it will work.

Frank
--
_____ ____
/ / / Frank Robijn Internet: Robijn@Strw.LeidenUniv.NL
/___ /___/ Sterrewacht Leiden Bitnet: Robijn@HLERUL51
/ / \ Phone (31) 71 275841 Local: Robijn@HL628
/ / \ Fax : (31) 71 275819 Snail: P.O.Box 9513, 2300 RA Leiden,
The Netherlands
Language Documentation; was: Re: Inverting indices? [message #2489 is a reply to message #2353] Fri, 08 July 1994 08:49 Go to previous message
caron is currently offline  caron
Messages: 16
Registered: May 1994
Junior Member
> Well, to be correct, a 'true' value is any 'odd' value, i.e. LSB is 1.
> A 'false' value is any 'even' value, i.e. LSB is 0. The NOT operator
> does a bitwise NOT, so this works out. WHERE, however, returns indices
> of all *nonzero* elements, so use -1 because (NOT -1) is 0.

Ive been wondering about this. Could RSI please get this kind of stuff
into their documents? As a C programmer, I've been used to 0 or not 0 logic.
Also, you could mention that all your logical operations are bitwise (I think),
e.g "and" is "&" not "&&".

As a general comment to RSI, your manuals seem written for the casual,
scientist-type (i.e. non-programmer). Sort of a "dont confuse them" attitude.
Your language description is woefully vague to the eyes (ears?) of this
programmer. How about a "programmer's description" of the language?

Comments?
Re: Inverting indices? [message #2498 is a reply to message #2448] Thu, 07 July 1994 08:57 Go to previous message
dball is currently offline  dball
Messages: 4
Registered: June 1994
Junior Member
In article <2uslco$m4k@highway.LeidenUniv.nl>, robijn@Strw.LeidenUniv.NL (Frank Robijn) writes:
> In article <kkobayas.772907009@husc9.harvard.edu>,
> Ken Kobayashi <kkobayas@husc9.harvard.edu> wrote:
>>
>> Am I making sense? I just need to do j=OPPOSITE(i,10) so that when
>> i=[1,3,5] it'll return j=[0,2,4,6,7,8,9].
>>
>> I couldn't find a built-in routine that does this. I tried the following
>> code:
>>
>> FUNCTION opposite,idx,n
>> k = bytarr(n)
>> k(idx)=1
>> return,where(not k)
>> end
>>
>> but this didn't seem to work for some reason.
>
> A 'false' value in IDL is -1, not 1. So change k(idx)=1 to k(idx)=-1 and
> it will work.
>
> Frank

Well, to be correct, a 'true' value is any 'odd' value, i.e. LSB is 1.
A 'false' value is any 'even' value, i.e. LSB is 0. The NOT operator
does a bitwise NOT, so this works out. WHERE, however, returns indices
of all *nonzero* elements, so use -1 because (NOT -1) is 0.

-- Dave
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: simultaneous run
Next Topic: Annotating Radar Images

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

Current Time: Wed Oct 08 13:42:00 PDT 2025

Total time taken to generate the page: 0.00540 seconds