I have this code in a file called 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
Then in the file that I'm running, I have:
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);
For some reason, I'm getting this error when I try to run it:
"Error using createTeamDict (line 6) Not enough input arguments."
Any ideas why this might be the case?
Thanks,
Going with our comments, the file wasn't saved. Simply save the file and it'll work.
For efficiency, there's no need to loop over each key/value pair to create your containers.Map
that way. You can initialize the dictionary with a set of input key/value pairs:
team_dict = containers.Map(team_names, num2cell(team_ids));
We get:
>> team_dict
team_dict =
Map with properties:
Count: 7
KeyType: char
ValueType: double
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.