Merging multiple dictionaries with cell arrays
9 次查看(过去 30 天)
显示 更早的评论
How can one merge multiple dictionaries A and B with cell arrays to get C. Ideally, with some warning for clashes.
A = dictionary( ...
{ ...
"type", ...
"value" ...
}, ...
{...
"temporary", ...
1 ...
} ...
)
B = dictionary( ...
{ ...
"color" ...
}, ...
{...
"blue" ...
} ...
)
C = dictionary( ...
{ ...
"type", ...
"value", ...
"color" ...
}, ...
{...
"temporary", ...
1, ...
"blue" ...
} ...
)
0 个评论
采纳的回答
Stephen23
2025-6-3
编辑:Stephen23
2025-6-3
A = dictionary({"type","value"},{"temporary",1});
B = dictionary({"color"},{"blue"});
If you want to create a new merged dictionary without modifying the originals:
C = dictionary(A.keys, A.values);
C(B.keys) = B.values
If you can modify one of the original dictionaries:
A(B.keys) = B.values
You would have to experiment to find out how it behaves with duplicate keys.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dictionaries 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!