UNIQ

The UNIQ function returns the subscripts of the unique elements in an array. Note that repeated elements must be adjacent in order to be found. This routine is intended to be used with the SORT function: see the examples below. This function was inspired by the Unix uniq(1) command.

UNIQ returns an array of indices into the original array. Note that the index of the last element in each set of non-unique elements is returned. The following expression is a copy of the sorted array with duplicate adjacent elements removed:

Array (UNIQ( Array ))

UNIQ returns 0 (zero) if the argument supplied is a scalar rather than an array.

This routine is written in the IDL language. Its source code can be found in the file uniq.pro in the lib subdirectory of the IDL distribution.

Calling Sequence

Result = UNIQ( Array [, Index] )

Arguments

Array

The array to be scanned. For UNIQ to work properly, the array must be sorted into monotonic order unless the optional parameter Idx is supplied.

Index

This optional parameter is an array of indices into Array that order the elements into monotonic order. That is, the expression:

Array ( Index )

yields an array in which the elements of Array are rearranged into monotonic order. If the array is not already in monotonic order, use the command:

UNIQ(Array, SORT(Array))

Examples

Find the unique elements of an unsorted array:

array = [1, 2, 1, 2, 3, 4, 5, 6, 6, 5] ; Create an array .

b = array(UNIQ(array, SORT(array))) ; Variable B holds an array containing the sorted, unique values in array.

PRINT, b

IDL prints

1    2    3    4    5    6

See Also

SORT , WHERE