Create One large containers.map from multiple maps
10 views (last 30 days)
Show older comments
xander fong
on 28 Jul 2015
Answered: Cam Salzberger
on 30 Jul 2015
Hello, So i created a file of 50 or so risk maps using the for loop: for i=1:numel(mdata) mmap{i}=containers.Map(mdata{i}.TagLevel1,mdata{i}.TagLevel3); end
In doing so, I created a 50x1 cell array in which every cell contains a map for the corresponding date. How do I create one large map/file from all 50 of these?
0 Comments
Accepted Answer
Cam Salzberger
on 30 Jul 2015
Hi Xander,
From your question, I believe that you are trying to create a single "containers.Map" object to hold all of the data in different tags. Your input to this is a cell array, "mdata", where each cell contains a struct. Assume we have the following sample "mdata":
mdata{1} = struct('TagLevel1','mdata1','TagLevel3',1);
mdata{2} = struct('TagLevel1','mdata2','TagLevel3',2);
mdata{3} = struct('TagLevel1','mdata3','TagLevel3',3);
Now you can create an empty "containers.Map" object, and add the key-value pairs to it in a loop, as shown below:
mmap = containers.Map;
for k = 1:numel(mdata)
mmap(mdata{k}.TagLevel1) = mdata{k}.TagLevel3;
end
Alternatively, you can extract the data from "mdata" in vector format, and use that to create "mmap" all at once:
mdataStruct = [mdata{:}]; % Create struct array instead of cell array of structs
keySet = {mdataStruct.TagLevel1}; % Create cell array of keys
valSet = {mdataStruct.TagLevel3}; % Create cell array of values
mmap = containers.Map(keySet, valSet);
I hope that this information helps.
-Cam
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!