containers.Map keys value not match

조회 수: 10 (최근 30일)
Safwana Razak
Safwana Razak 2019년 11월 8일
댓글: Walter Roberson 2019년 11월 11일
Hi,
i try using containers.Map function to automate my table value into certain keys but end end up with this error:
"Specified key type does not match the type expected for this container."
i refer back my code, the data for key data is correct data type. anyone can assist me how to solve this problem?
here i attach my code:
labelMap = containers.Map('KeyType','double','ValueType','char');
keySet = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
valueSet = {'air_conditioner','car_horn','children_playing','dog_bark','drilling','engine_idling','gun_shot','jackhammer','siren','street_music'};
labelMap = containers.Map(keySet,valueSet);
current_class = reference_table(strcmp(reference_table.fsID, PCG.filename), :).classID;
feature_table.class = {labelMap(current_class)};
thanks.
  댓글 수: 2
Daniel M
Daniel M 2019년 11월 9일
What is the output of current_class?
Safwana Razak
Safwana Razak 2019년 11월 11일
my output should be keyset value, 0 or 1 or 2 and so on. i try to do classification actually.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 11월 9일
편집: Walter Roberson 2019년 11월 11일
We can suspect strongly from your use of {} around the call to labelMap that you are expecting current_class to be a vector, and expecting the call to labelMap to return a comma separated list, that you would then capture all of in the {} .
However, you defined the key as scalar, not as vector, and passing a vector key in where a scalar key is expected is going to get you exactly that error message.
You should instead use
feature_table.class = arrayfun(@(C) labelMap(C), current_class, 'uniform', 0);
  댓글 수: 2
Safwana Razak
Safwana Razak 2019년 11월 11일
my expecting output is keyset value, 0 or 1 or 2 and so on.
Walter Roberson
Walter Roberson 2019년 11월 11일
Your current_class is returning a non-scalar under at least one condition. There might not be a match, or there might be multiple matches.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by