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!