Create One large containers.map from multiple maps
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Cam Salzberger
2015-7-30
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!