0

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,

6
  • Are you sure your current working directory contains createTeamDict.m? Type in ls in your Command Prompt, push ENTER and see if the file is there. If not, you need to figure out where the file is, change your working directory to where that file is, then run the command again. Commented Oct 27, 2015 at 21:06
  • BTW, there's no need to make a function to do that or looping over each key/value pair rather. Simply do team_dict = containers.Map(team_names, num2cell(team_ids)); Commented Oct 27, 2015 at 21:08
  • 1
    Did you save the file? Is there perhaps a variable called createTeamDict in your workspace? Try doing clear createTeamDict too while you're at it. Commented Oct 27, 2015 at 21:10
  • 1
    Sigh just hadn't saved, thanks guys Commented Oct 27, 2015 at 21:16
  • 1
    lol no problem. I've written an answer for self-containment. Commented Oct 27, 2015 at 21:18

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.