Merging multiple dictionaries with cell arrays
8 ビュー (過去 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!