필터 지우기
필터 지우기

containers.Map: The number of keys and values must be the same

조회 수: 6 (최근 30일)
I have the above mentioned issue when I try to run this code:
keys = [DS.UserNum];
valueSet = [DS.CarNum];
M = containers.Map(keys,valueSet)
UserNum Car Num
1 [123,257,345,235,553]
2 834
3 [111,156]
4 [111,445,642,164]
5 []
--> The number of keys and values must be the same. How can I correct that.

채택된 답변

Walter Roberson
Walter Roberson 2022년 5월 6일
valueSet = {DS.CarNum};
  댓글 수: 2
Mehdi Jaiem
Mehdi Jaiem 2022년 5월 7일
Thank ! that was it. But this is weird as on the mathwork website you got the following format
keySet = {'Jan','Feb','Mar','Apr'};
valueSet = [327.2 368.2 197.6 178.4];
M = containers.Map(keySet,valueSet)
keySet is put between {} and valueSet between []
Walter Roberson
Walter Roberson 2022년 5월 7일
In that example, the keys are character vectors, and the values are scalar numeric. Character vectors are collections of characters.
In your code, the keys are scalar numeric, and the values are vectors of numeric — collections of numbers.
In both cases, collections use {} and scalars use []

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by