Search code examples
matlab

How to use Hash Tables (dictionaries) in MATLAB?


I need to acces data by string index, like table('one') %returns 1. Is there such a data structure in MATLAB? How is it implemented?


Solution

  • In recent versions of MATLAB, there's the containers.Map data structure. See MATLAB Map containers for more. This removes some of the restrictions when using STRUCTs. For example

    c = containers.Map
    c('foo') = 1
    c(' not a var name ') = 2
    keys(c)
    values(c)