Non-intuitive result with !Null in Where() [message #85610] |
Wed, 21 August 2013 09:42  |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
This is not what I expected. If there are no elements, how can "count" be non-zero? I was hoping that Where() would return !Null and "count" would be 0.
IDL> print, n_elements(!Null)
0
IDL> print, where(!Null ne 0, count)
0
IDL> print, count
1
IDL> print, where(!Null ne 0, count, /NULL)
0
IDL> print, count
1
IDL> print, !Null[0]
% Expression must be an array in this context: !NULL.
IDL> print, (!Null)[0]
% Variable is undefined: <UNDEFINED>.
The Where function is telling me I can access !Null at element 0, but I cannot.
IDL> print, !version
{ x86_64 darwin unix Mac OS X 8.0 Jun 17 2010 64 64}
|
|
|
|
|
Re: Non-intuitive result with !Null in Where() [message #85616 is a reply to message #85610] |
Wed, 21 August 2013 16:51  |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Wed, 21 Aug 2013 09:42:25 -0700 (PDT), Matthew Argall wrote:
> This is not what I expected. If there are no elements, how can "count" be non-zero? I was hoping that Where() would return !Null and "count" would be 0.
>
> IDL> print, n_elements(!Null)
> 0
> IDL> print, where(!Null ne 0, count)
> 0
> IDL> print, count
> 1
> IDL> print, where(!Null ne 0, count, /NULL)
> 0
> IDL> print, count
> 1
> IDL> print, !Null[0]
> % Expression must be an array in this context: !NULL.
> IDL> print, (!Null)[0]
> % Variable is undefined: <UNDEFINED>.
>
>
> The Where function is telling me I can access !Null at element 0, but I cannot.
>
This is not true. In your words, the Where function is telling you,
that the expression !null ne 0 has one element, which is not equal 0.
And the position of this element is 0.
IDL> expr=!null ne 0
IDL> help,expr[0]
<Expression> BYTE = 1
Heinz
|
|
|