Main Content

values

Values of dictionary

Since R2022b

    Description

    v = values(d) returns an N-by-1 array of values from the specified dictionary, where N is the number of entries in the dictionary. Values are returned in the order in which the entries were added to the dictionary.

    example

    v = values(d,"cell") optionally return the values as a cell array.

    example

    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 values to return an array containing the values stored in the dictionary.

    v = values(d)
    v = 3×1 string
        "Unicycle"
        "Bicycle"
        "Tricycle"
    
    

    Loop over and display each value of the dictionary.

    for currentVal = values(d)'
        disp("value: " + currentVal)
    end
    value: Unicycle
    value: Bicycle
    value: Tricycle
    

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

    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 values to return an array containing the values stored in the dictionary as a cell array.

    v = values(d,"cell")
    v=3×1 cell array
        {["Unicycle"]}
        {["Bicycle" ]}
        {["Tricyle" ]}
    
    

    Input Arguments

    collapse all

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

    Output Arguments

    collapse all

    Dictionary values, returned as an N-by-1 array of values from the specified dictionary, where N is the number of entries in the dictionary. Values are returned in the order in which the entries were added to the dictionary.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2022b

    expand all