How can I store arrays in container maps

조회 수: 8 (최근 30일)
Tsz Tsun
Tsz Tsun 2022년 8월 18일
댓글: Tsz Tsun 2022년 8월 18일
Hi all, I am very new to matlab and I have some questions on container map. I would like to know how to store arrays under container map. I have the following simple code, but it cannot give me the array desired. How can I do that?
keySet = {'1,1', '1,2'}
keySet = 1×2 cell array
{'1,1'} {'1,2'}
valueSet = [[2 3], [3 4]];
M = containers.Map(keySet,valueSet)
Error using containers.Map
The number of keys and values must be the same.
M('1,1')
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2022년 8월 18일
valueSet must have 2 elements, corresponding to keySet
%Using [] will result in joining all elements
valueSet = [[2 3], [3 4]]
valueSet = 1×4
2 3 3 4
keySet = {'1,1', '1,2'};
%use cell array
valueSet = {[2 3], [3 4]};
M = containers.Map(keySet,valueSet);
M('1,1')
ans = 1×2
2 3
Tsz Tsun
Tsz Tsun 2022년 8월 18일
Thanks a lot! : )

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by