SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 2 Vol 1

MATCH

Name:
    MATCH (LET)
Type:
    Let Subcommand
Purpose:
    Match a column of values to another column of numbers and return the index of the matching value.
Description:
    This command works on two columns of numbers. The first column contains a set of numbers. Each value in the second column is matched against the first column. The closest value, as determined by the smallest absolute value in the difference between the numbers, is considered the match. This command returns the index, not the actual value, of the first array where the match occurs. The returned column of numbers will then be an array of index numbers.

    This is a utility operation. That is, the index numbers are generally not of interest themselves but are used in subsequent computations.

    An alternative syntax supplies a third variable. Instead of returning an index, the MATCH command uses the index to extract the value corresponding to the index of this third variable. Generally, this is the ultimate goal (i.e., we would use the index to extract values of another variable).

Syntax 1:
    LET <y> = MATCH <x> <val>             <SUBSET/EXCEPT/FOR qualification>
    where <x> is the variable containing a set of numbers;
                <val> is a number, parameter, or variable that will be matched against the values in <x>;
                <y> is a variable (of length equal to <val>) that contains the index (of <x>) where the match occurs;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This syntax returns the index value.

Syntax 2:
    LET <y> = MATCH <x> <val> <z>                       <SUBSET/EXCEPT/FOR qualification>
    where <x> is the variable containing a set of numbers;
                <val> is a number, parameter, or variable that will be matched against the values in <x>;
                <z> is a variable (of length equal to <x>) that contains the values to be extracted and placed in <y>;
                <y> is a variable (of length equal to <val>) that contains the values of <z> corresponding to the matched indices (of <x>);
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This syntax returns values of corresponding to the matched indices.

Examples:
    LET Y = MATCH X VALUE
    LET Y = MATCH X VALUE SUBSET X > 0 1
    LET Y = MATCH X VALUE Z
    LET Y = MATCH X VALUE Z SUBSET X > 0
Default:
    None
Synonyms:
    None
Related Commands:
    SEQUENCE = Generate a patterned sequence of values.
    SORT = Sort a column of numbers.
    RANK = Rank a column of numbers.
    CODE = Code a column of numbers.
Applications:
    Data Transformation
Implementation Date:
    2001/10
Program 1:
    LET Y = NORMAL RANDOM NUMBERS FOR I = 1 1 100
    LET VAL = SEQUENCE -3 1 3
    LET Y2 = MATCH Y VAL
    SET WRITE DECIMALS 3
    PRINT VAL Y2
Program 2:
    LET Y = NORMAL RANDOM NUMBERS FOR I = 1 1 100
    LET VAL = SEQUENCE -3 1 3
    LET Z = SEQUENCE -10 1 -1
    LET Y2 = MATCH Y VAL Z
    SET WRITE DECIMALS 3
    PRINT Y Z
    PRINT VAL Z2

Date created: 10/23/2001
Last updated: 4/4/2003
Please email comments on this WWW page to alan.heckert@nist.gov.