MATLAB Answers

Dictionaries of Hashtables in MATLAB?

125 views (last 30 days)
Philip
Philip on 13 Nov 2011
Edited: John Kelly on 26 Feb 2015
Hi all,
Is there a way to create a hash table or dictionary in MATLAB such that I can retrieve a set of values based on a key?
I also need to append more entries to the end of the list, given a key. I tried importing a hashtable from java.util.Hashtable, but the "add" method overwrites the current entries if a key already exists...
Thanks for all your help!

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Nov 2011
Edited: John Kelly on 26 Feb 2015

  3 Comments

Philip
Philip on 14 Nov 2011
That looks like it might do the trick, but I can only see how to initialise the map. Have you used this before? Do you know how I can add keys and values one by one? Can the map contain more than one value for a single key?
Philip
Philip on 14 Nov 2011
(I need to collect the keys and values inside a loop, so I don't know them beforehand - this means unfortunately I cannot enter all the data at once.)
Philip
Philip on 14 Nov 2011
To answer my own question there, it seems the solution for adding values without overwriting the previous entries is:
mapName('key_string') = [mapName('key_string') [1 2 3]];
Thanks for your suggestion. I think this will work!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by