Main Content

entries

Key-value pairs of dictionary

Since R2022b

    Description

    E = entries(d) returns a table containing the key-value pairs of the specified dictionary.

    example

    E = entries(d,format)specifies the output format as a table or a structure. For example, entries(d,"struct") returns a structure containing the key-value pairs of d. Use this option for data types that are not compatible with tables.

    example

    Examples

    collapse all

    Create a dictionary containing several key-value pairs.

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

    Use entries to return a table containing the entries stored in d.

    E = entries(d)
    E=3×2 table
        Key      Value   
        ___    __________
    
         1     "Unicycle"
         2     "Bicycle" 
         3     "Tricyle" 
    
    

    Create a dictionary containing several key-value pairs.

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

    Use entries and specify the output format as "struct" to return a struct array containing the entries stored in d.

    E = entries(d,"struct")
    E=3×1 struct array with fields:
        Key
        Value
    
    

    Input Arguments

    collapse all

    Dictionary, specified as a dictionary object. If d is unconfigured, entries throws an error.

    Output format, specified as one of these values:

    • "table" — Return key-value pairs in a table. This format is the default output format.

    • "struct" — Return an n-by-1 struct array, where each of the n struct elements has the fields key and value corresponding to each of the n entries in the specified dictionary. Use this option for data types that are not compatible with tables.

    • "cell" — Return key-value pairs in a n-by-2 cell array where n is the number of entries, the first column contains keys, and the second column contains values.

    Extended Capabilities

    Version History

    Introduced in R2022b

    expand all