Main Content

types

Types of dictionary keys and values

Since R2022b

    Description

    example

    [keyType,valueType] = types(d) returns the data types of keys and values of the specified dictionary. If d is an unconfigured dictionary, then types returns a <missing> string scalar.

    keyType = types(d) returns the data types of keys.

    Examples

    collapse all

    Create a dictionary containing three key-value pairs that map numbers to strings.

    names = ["Unicycle" "Bicycle" "Tricycle"];
    wheels = [1 2 3];
    d = dictionary(wheels,names)
    d =
    
      dictionary (double --> string) with 3 entries:
    
        1 --> "Unicycle"
        2 --> "Bicycle"
        3 --> "Tricycle"
    

    Use types to return the types for the keys and values of the dictionary.

    [keyType,valueType] = types(d)
    keyType = 
    "double"
    
    valueType = 
    "string"
    

    Input Arguments

    collapse all

    Dictionary, specified as a dictionary object.

    Output Arguments

    collapse all

    Data type of dictionary keys, returned as a string scalar.

    Value data type, returned as a string scalar.

    Version History

    Introduced in R2022b