Create One large containers.map from multiple maps
10 ビュー (過去 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 で Data Exploration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!