Create One large containers.map from multiple maps
조회 수: 12 (최근 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!