Filter löschen
Filter löschen

Matlab container map with repeated keys

4 Ansichten (letzte 30 Tage)
Pontus Vikstål
Pontus Vikstål am 3 Apr. 2019
Kommentiert: Pontus Vikstål am 3 Apr. 2019
Consider the following container map
k = ["Jan" "Feb" "Jan" "Mars"]; % Notice that there are two repeated elements which is "Jan"
v = [10 20 30 15];
M = containers.Map(k,v)
% The output is
[keys(M); values(M)]
%{
{'Feb'} {'Jan'} {'Mars'}
{[ 20]} {[ 30]} {[ 15]}
%}
Notice that in the output only the last of the two repeated elements in the list k was included. What I instead would like to have is
%{
{'Feb'} {'Jan'} {'Mars'}
{[ 20]} {[ 10, 30]} {[ 15]}
%}
Is it possible?
  4 Kommentare
Adam
Adam am 3 Apr. 2019
Yes, that is how you would need to add them if you have them all upfront, which is fairly easy. It's just adding later elements to the map that is more convoluted.
Pontus Vikstål
Pontus Vikstål am 3 Apr. 2019
Alright, I see!
Thanks for the help!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Variables 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!

Translated by