Both the real and imaginary parts of a complex number must be zero for the number to be considered zero. If /NULL is set, and no matches are found, then WHERE returns the value !NULL. Returns a longword vector containing the subscripts of non-zero array elements matching the specified conditions. Example 1 Create an integer array 0,1,2.9 array = INDGEN( 10) PRINT, 'array = ', array Find the subscripts of all elements that are greater than 5 B = WHERE(array GT 5, count, COMPLEMENT=B_C, NCOMPLEMENT=count_c) Print how many and which elements met the search criteria: PRINT, 'Number of elements > 5: ', count PRINT, 'Subscripts of elements > 5: ', B PRINT, 'Number of elements 5: 4 Subscripts of elements > 5: 6 7 8 9 Number of elements <= 5: 6 Subscripts of elements <= 5: 0 1 2 3 4 5 Syntax See Additional Examples for more information on using WHERE. Or, Use Count to get the number of nonzero elements: index = WHERE(array GT 5, count) Only subscript the array if it is safe: IF count NE 0 THEN array = 5 Examples For example: Use /NULL, if no elements match then array will not be modified: array = 5 To avoid this problem, you should either use /NULL or check the Count argument before indexing. If you use this result as an index into another array without checking for –1 first, then this will return the last element of the array. If the NULL keyword is not set, and all the elements of Array_Expression are zero, then WHERE returns a scalar integer with a value of –1. Frequently the result of WHERE is used as a vector subscript to select elements of an array using given criteria.
The length of the resulting vector is equal to the number of nonzero elements in Array_Expression. The WHERE function returns a vector that contains the one-dimensional subscripts of the nonzero elements of Array_Expression.