Merging multiple dictionaries with cell arrays
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Stephen23
am 3 Jun. 2025
Bearbeitet: Stephen23
am 3 Jun. 2025
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dictionaries finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!