0
我在使用特定键(我使用containers.Map)访问值时遇到了一些麻烦。我已经成立了一个名为地图team_dict
看起来像:MATLAB:容器混淆行为。地图
{ 'Columbia' : 'www.columbia.com', 'Bates' : 'www.bates.com', ... }
我尝试做
url = team_dict(currentKey);
对应于关键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。
任何想法为什么会发生这种情况?
感谢
你介意拟订之间{的差异}和[]或指着我的多方向关于它的信息?忽略,只是发现:http://www.mathworks.com/help/matlab/matlab_prog/what-is-a-cell-array.html – bclayman
是的,这是链接。如果你的问题得到解决,你介意接受答案吗? – scmg