【发布时间】:2015-10-27 22:16:57
【问题描述】:
我在使用特定键访问值时遇到了一些问题(我使用的是 containers.Map)。我设置了一个名为team_dict 的地图,看起来像:
{ 'Columbia' : 'www.columbia.com', 'Bates' : 'www.bates.com', ... }
我试着去做
url = team_dict(currentKey);
访问 Map 中 key currentKey 对应的值。
以下是相关代码:
allKeys = keys(team_dict);
%loop through all keys
for i = 1 : length(allKeys)
%for current key (team name), getTeam
currentKey = allKeys(i);
disp(currentKey);
url = team_dict(currentKey);
end
我收到此错误:
Error using containers.Map/subsref
Specified key type does not match the type expected for this container.
Error in project (line 27)
teamPlayers = getTeam(team_dict(currentKey), currentKey);
奇怪的是,当我拨打disp(currentKey) 时,“哥伦比亚”会正确打印出来。另外,在交互式提示中,当我这样做时
team_dict('Columbia')
我找回了正确的 URL。
知道为什么会这样吗?
谢谢
【问题讨论】:
标签: matlab