Main Content


Determine if two dictionary keys are the same



    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


    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.

    ans = logical

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

    Y.field1 = 3;
    ans = logical

    Input Arguments

    collapse all

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

    Version History

    Introduced in R2022b