EXTRAC

The EXTRAC function returns as its result any rectangular sub-matrix or portion of the parameter array. Note that it is usually more efficient to use the array subscript ranges (the ":" operator; see Subscript Ranges ) to perform such operations. The main advantage to EXTRAC is that, when parts of the specified subsection lie outside the bounds of the array, zeros are entered into these outlying elements.

EXTRAC was originally a built-in system procedure in the PDP-11 version of IDL, and was retained in that form in the original VAX/VMS IDL for compatibility. Most applications of the EXTRAC function are more concisely written using subscript ranges (e.g., X(10:15)). EXTRAC has been rewritten as a library function that provides the same interface as the previous versions.

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

Calling Sequence

Result = EXTRAC( Array, C 1 , C 2 , ..., C n , S 1 , S 2 , ..., S n )

Arguments

Array

The array from which the subarray will be copied.

C i

The starting subscript in Array for the subarray. There should be one C i for each dimension of Array . These arguments must be integers.

S i

The size of each dimension. The result will have dimensions of ( S 1 , S 2 , ..., S n ). There should be one S i for each dimension of Array . These arguments must be non-negative.

Examples

Extracting elements from a vector:

A = FINDGEN(1000) ; Create a 1000 element floating-point vector with each element set to the value of its subscript.

B = EXTRAC(A, 200, 300) ; Extract 300 points starting at A[200] and extending to A[499].

In the next example, the first 49 points extracted-- B[0] to B[49] --lie outside the bounds of the vector and are set to 0. B[50] is gets the value of A[0] , B[51] gets the value of A[1] which is 1. Enter:

A = FINDGEN(1000) ; Create a 1000 element vector.

B = EXTRAC(A, -50, 100) ; Extract 50 elements, 49 of which lie outside the bounds of A.

The following commands illustrate the use of EXTRAC with multi-dimensional arrays. Enter:

A = INTARR(64,64) ; Make a 64 by 64 array.

B = EXTRAC(A, 20, 30, 32, 32) ; Extract a 32 by 32 portion starting at A(20,30).

As suggested in the discussion above, a better way to perform the same operation as the previous line is:

B = A(20:51, 30:61) ; Use the array subscript operator instead of EXTRAC.

Extract the 20th column and 32nd row of A:

B = EXTRAC(A, 19, 0, 1, 64) ; Extract 20th column of A.

B = EXTRAC(A, 0, 31, 64, 1) ; Extract 32nd row of A.

Take a 32 BY 32 matrix from A starting at A(40,50):

B = EXTRAC(A, 40, 50, 32, 32) ; Note that those points beyond the boundaries of A are set to 0.

See Also

Subscript Ranges .