File Exchange

image thumbnail


version (13.7 KB) by Roland
MapNested is a subclass from '' which implements nested maps (easy multi-key access)


Updated 08 Jul 2017

GitHub view license on GitHub

Matlab implementation for nested maps (map of maps). This class implements easy set and get access for multible keys. The syntax is the following: Generate a new MapNested object:
NMapobj = MapNested(); %generate a new object
Write values to the Map (2 possibilites):

%possibility 1 syntax:
NMapobj('key1', 'key2', 'key3') = 10; %assign value 10 to the keyList
NMapobj({'key1', 'key2', 'key4'}) = 5; %assign value 5 using a cell array for the keyList

%possibility 2 - use the 'setValueNested' function
NMapobj = setValueNested(NMapobj, {key1, key2, key3}, 10);
NMapobj = setValueNested(NMapobj, {key1, key2, key4}, 5);
Retrieve values from the Map (2 possibilites):

%possibility 1:
value1 = NMapobj(key1, key2, key3); %returns '10'
value2 = NMapobj({key1, key2, key4}); %return '5'

%possibility 2 - using 'getValueNested' - function
value1 = getValueNested(NMapobj ,{key1, key2, key3}); %returns '10'
value2 = getValueNested(NMapobj ,{key1, key2, key4}); %returns '5'
Call superclass Methods (see containers.Map: eg isKey, keys, length, remove, size, values):

Retrieve properties (see containers.Map: eg. Count, KeyType, ValueType):
Delete Entries:

NMapobj('Key') = [];
remove(NMapobj, 'Key');
This function is a subclass from Matlabs ''-class:

ATTENTION: Cell-arrays can not be assigned to the map

NMapobj('key1', 'key2', 'key3') = {'a', 'cell', 'array'}; %throws error see:

Cite As

Roland (2020). RolandRitt/Matlab-NestedMap (, GitHub. Retrieved .

Comments and Ratings (5)

I am loving the ability to have a map with multiple keys. However, I'm confused about using accessing the keys and values. With a basic container.Map, I get a list of actual keys or actual values when I use mymap.keys. However, I get a struct with no useful information when my map is a NestedMap.


Some more links, it seems that you need to go through some loops to reproduce default behavior in the cases you don't want to modify.
For example you might expose private properties and methods if you don't put checks for those. Not that i would care about that in this instance.


Otherwise I wouldn't mind, but I'd like to be able to call foo.values or foo.keys (without arguments).


Take a look at

disallowing . indexing for example hides inherited methods from map, like values, count and keys.


implemented 'isKey' method, to enable if a nested key is in the map, eg,:
*) M.isKey({Key1, Key2, Key3})
*) M.isKey(Key1, Key2, Key3)

remove entries by assinging empty array implemented:

Add '.' subsref for calling superclass-methods and properties

changed the class descripion and extended the test file

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux