dictionary

Methods

Method Reference: dictionary.insert

dictionary: d = insert (d, keys, values)

dictionary: d = insert (…, 'Overwrite', tf)

Add entries.

d = insert (d, keys, values) adds the entries of keys and values to d, as d(keys) = values does: values has the size of keys, or is one value for all, and both are converted to the types of d, which an unconfigured dictionary takes from them. A key already present has its value replaced and keeps its position.

d = insert (…, 'Overwrite', tf) with tf false leaves the value of a key already present unchanged, and a key repeated in keys takes its first value; it still adds the keys not yet present. tf is a logical or numeric scalar, true by default. The option name is matched in any case.

See also: dictionary.remove, dictionary.lookup, dictionary.isKey

Source Code: dictionary

insert adds entries as assignment does. With 'Overwrite', false the values of keys already present are kept, and only new keys are added.

 stock = dictionary (string ({'pen', 'ink'}), [12, 4])
stock =

  dictionary (string ⟼ double) with 2 entries:

    "pen" ⟼ 12
    "ink" ⟼ 4
 stock = insert (stock, {'ink', 'tape'}, [9, 7])
stock =

  dictionary (string ⟼ double) with 3 entries:

    "pen"  ⟼ 12
    "ink"  ⟼ 9
    "tape" ⟼ 7
 stock = insert (stock, {'pen', 'glue'}, [0, 3], 'Overwrite', false)
stock =

  dictionary (string ⟼ double) with 4 entries:

    "pen"  ⟼ 12
    "ink"  ⟼ 9
    "tape" ⟼ 7
    "glue" ⟼ 3