Wednesday, 15 June 2011

Merge cell array of maps by key in Matlab -


Count (value) for the given event by looking at a cell array of

container.map ).

For example:

  map = {container.map ({'a', 'b'}, {1,2}), container. Map ({'b', 'c'}, {4,1})}; Merge Maps ans = Map (A -> 1, B -> 6, C -> 1)   

I can reach such a distance:

  maps = {...}; Res = container.map (); CMapC = map for cMap = cMapC {1}; CKeyC = cKey = cKeyC {1} for keys (cMap {1}); If hacks (race, ck) ridge (ck) = ridge (ck) + ciemax (ck); And ridge (ck) = cemap (ck); End of the end   

should work (untested), but whose "efficiency" and readability are least susceptible to say. What is a better solution?

Please note that there is currently no index for events, so it is cumbersome to use sparse matrix instead of map.

Not sure about readability, but it is probably more efficient:

  allKeys0 = cellfun (@keys, maps, 'uniformoptput', incorrect); [All, ~, m] = unique ([all keys 0:}]); AllValues0 = cellfun (@values, maps, 'uniformoputput', false); AllValues ​​= cell2mat ([allValues0 {:}]); Par = array (@ (x) amount (all values ​​(m == x)), 1: number (all of)); Merged map = container. Map (all of, par);    

No comments:

Post a Comment