Main Content


Determine if two dictionary keys are the same

Since R2022b



    tf = keyMatch(A,B) returns 1 (true) if arrays A and B are 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 ensure 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 so that X and Y are 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