Main Content

keyMatch

Determine if two dictionary keys are the same

    Description

    example

    tf = keyMatch(A,B) returns 1 (true) if arrays A and B are have the same class, properties, dimensions, and values and returns 0 (false) otherwise.

    NaN, NaT, <undefined> categorical elements, and <missing> values are considered to be equal to other such values. Handle objects match if they are the same handle.

    The keyMatch function determines equivalence on the properties of the input. For custom classes keyMatch may need to be overloaded to insure correct equivalence. For more information on using custom classes with dictionary, see Dictionaries and Custom Classes

    Examples

    collapse all

    Dictionaries map unique keys to values. Use the function keyMatch to determine if keys are the same

    Create two structures with two fields.

    X = struct("field1",1,"field2",2);
    Y = struct("field1",1,"field2",2);

    Use keyMatch to determine if X and Y are the same as dictionary keys.

    keyMatch(X,Y)
    ans = logical
       1
    
    

    Change field1 of Y and X and Y will now be different as dictionary keys.

    Y.field1 = 3;
    keyMatch(X,Y)
    ans = logical
       0
    
    

    Input Arguments

    collapse all

    Inputs to be compared, specified as scalars, vectors, matrices, or multidimensional arrays

    Version History

    Introduced in R2022b