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

Home » Public Forums » archive » Re: error using statement: If.....then
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: error using statement: If.....then [message #54551 is a reply to message #54548] Tue, 26 June 2007 14:30 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Jun 26, 2:55 pm, Giuseppe Giovanni Salerno <g...@cam.ac.uk> wrote:
> Hi everybody, I am new on IDL and I will be very grateful if someone
> could help me
>
> I have an array of value (X,Y) and I want all Y data negative equals
> to 1:
> x y
> 1 84
> 2 90
> 3 14
> 4 -75
> 5 -95
> 6 -27
>
> so I guess the correct way to apply this filtering is working with IF
> and THEN:
>
> IF x LT 0 then x = 1
>
> but I got an error:
> "Expression must be a scalar or 1 element array in this context: <BYTE
> Array[2, 6]"
> How I can resolve this problem?
>
> Thanks in advance
> Cico

A couple points:

1. Array indices start at 0 in IDL, so the x column in your table of
values should be 0..5.

2. The technique you are trying above (i.e. with an IF statement) also
needs a FOR loop, to loop over each individual element. This is not
the best technique for IDL.

3. Use the WHERE statement to do things like the above. How about:

negIndices = where(x lt 0, nNegative)
if (nNegative gt 0) then x[negIndices] = 1

This could be done like:

x[where(x lt 0)] = 1

if you know that there will always be some negative values in x. (But
I would always check.)

Mike
--
www.michaelgalloy.com
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: loading colors in tvscl
Next Topic: Segmentation fault: IDL Version 6.3 (linux x86 m32)+Debian SID

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

Current Time: Thu Oct 23 08:37:03 PDT 2025

Total time taken to generate the page: 4.32056 seconds