|
Re: data comparison [message #44270 is a reply to message #44269] |
Wed, 01 June 2005 20:08  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
angela wrote:
> I am trying to extract specific values from an array, datax (string
> array[1,300]).
> When I type the command
>
> print,datax GE 100
>
> it works fine and it gives me the correct answer. But when I type
>
> print,datax GE x
>
> where x has been defined in the program earlier as 100 and is an
> integer array[1]
> the result is -1 which is wrong since there are values in this array
> that are greater or equal than 100.
> Does anyone have an idea what is going on?
You have been bitten by a common pitfall. The clue is that x is a
single-element array, not a scalar. The result of an arithmetic or
comparison operation between two arrays of different length is an array
with the shorter length, eg
IDL> help, fltarr(10)+fltarr(5)
<Expression> FLOAT = Array[5]
So when you do
IDL> print,datax GE x
you are comparing the first elements of datax with the first element of
x and discarding the rest. Try
IDL> print,datax GE x[0]
or
IDL> x = x[0]
IDL> print,datax GE x
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: data comparison [message #44271 is a reply to message #44270] |
Wed, 01 June 2005 19:25  |
angela
Messages: 7 Registered: June 2005
|
Junior Member |
|
|
Thank you! I tried both and they still give me the same wrong answer
-1.
Any other suggestions?
Thank you for the help,
Angela
Benjamin Hornberger wrote:
> angela wrote:
>> I am trying to extract specific values from an array, datax (string
>> array[1,300]).
>> When I type the command
>>
>> print,datax GE 100
>>
>> it works fine and it gives me the correct answer. But when I type
>>
>> print,datax GE x
>>
>> where x has been defined in the program earlier as 100 and is an
>> integer array[1]
>> the result is -1 which is wrong since there are values in this array
>> that are greater or equal than 100.
>> Does anyone have an idea what is going on?
>>
>> Thank you,
>> Angela
>>
>
> Why is your data array of string type? Try to convert one to the type of
> the other before comparison:
>
> print, datax GE string(x)
>
> or
>
> print, fix(datax) GE x
>
> Good luck,
> Benjamin
|
|
|
Re: data comparison [message #44274 is a reply to message #44271] |
Wed, 01 June 2005 14:44  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
angela wrote:
> I am trying to extract specific values from an array, datax (string
> array[1,300]).
> When I type the command
>
> print,datax GE 100
>
> it works fine and it gives me the correct answer. But when I type
>
> print,datax GE x
>
> where x has been defined in the program earlier as 100 and is an
> integer array[1]
> the result is -1 which is wrong since there are values in this array
> that are greater or equal than 100.
> Does anyone have an idea what is going on?
>
> Thank you,
> Angela
>
Why is your data array of string type? Try to convert one to the type of
the other before comparison:
print, datax GE string(x)
or
print, fix(datax) GE x
Good luck,
Benjamin
|
|
|