MATLAB:没有足够的输入参数(但我传入它们)

时间:2015-10-27 21:01:00

标签: matlab

我将此代码放在名为createTeamDict.m的文件中:

function [ team_dict ] = createTeamDict( team_names, team_ids )
%createTeamDict takes in a cell array of team names and a vector of
%corresponding team IDs and returns an appropriate dictionary, mapping team
%names to their IDs
    team_dict = containers.Map;
    for i = 1 : length(team_names)
       team_dict(team_names{i}) = team_ids(i); 
    end
end

然后在我正在运行的文件中,我有:

team_names = {'Trinity', 'SLU', 'Harvard', 'Columbia', 'Rochester', 'Yale', 'Upenn'};
team_ids = [11324 11351 11314 11326 11316 11315 11317];
team_dict = createTeamDict(team_names, team_ids);

出于某种原因,我在尝试运行时遇到此错误:

“使用createTeamDict时出错(第6行) 没有足够的输入参数。“

为什么会出现这种情况?

谢谢,

1 个答案:

答案 0 :(得分:1)

根据我们的评论,该文件未被保存。只需保存文件即可。

为了提高效率,您无需循环遍历每个键/值对,以此方式创建containers.Map。您可以使用一组输入键/值对初始化字典:

team_dict = containers.Map(team_names, num2cell(team_ids));

我们得到:

>> team_dict

team_dict = 

  Map with properties:

        Count: 7
      KeyType: char
    ValueType: double