I am currently trying to map some data within a month depending on 'Month'
, 'week'
, 'day'
.
This means that in principle I have three keys. I thought of following solutions to the problem:
1)
containers.Map(month,containers.Map(week,containers.Map(day,value)))
The problem with this solutions is to reference it I must use: How can I index a MATLAB array returned by a function without first assigning it to a local variable?.
And I find this solution rather "ugly".
2)
So another way would be to use a Map
with multiple keys. The containers documentation show that only a single dimension key is allowed.
Question:
Do you have any trick to solve this multiple key problem?
Update/Solution:
I ended using a concatenated string as a key (as suggested) I added following piece of code to make the containers.Map
as a proper multi-dimensional hashmap. Take a look below (I excluded week for simplification):
classdef example
properties
myMap % Map for storage
end
methods
function obj = example()
obj.myMap = containers.Map;
end
function obj2 = setVal(obj2,value,Month,DayType)
key = strcat(num2str(Month),'-',num2str(DayType));
obj2.myMap(key) = value;
end
function value = getValue(obj,Month,DayType)
key = strcat(num2str(Month),'-',num2str(DayType));
value = obj.myMap(key);
end
end