-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTeamColors.m
More file actions
69 lines (63 loc) · 1.9 KB
/
getTeamColors.m
File metadata and controls
69 lines (63 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
%getTeamColors.m - Get team colors in RGB format parsed from website
%
% Usage: [colors name league] = getTeamColors(teamname,league,filename)
%
% inputs:
% teamname - Any part of a team name (case insensitive), use 'all' for a
% complete listing
% league - (optional) League abbreviation of team
% filename - (optional) Path to team database file
%
% outputs:
% colors - n x 3 matrix of team colors
% name - Team name
% league - League name
%
% Will give a warning if more than one team matches the search criteria,
% unless team is set to 'all' and no output arguments are specified, in
% which case it will generate a series of links to set the colors.
%
% Nick Bottenus - 7/23/14
% Peter Hollender - 8/20/15
function [colors name league] = getTeamColors(teamname,leaguename,filename)
if(~exist('filename','var'))
filename=fullfile(fileparts(mfilename('fullpath')),'teamColors');
end
load(filename)
teamname=lower(teamname);
if strcmpi(teamname,'all')
teamname = ' ';
end
if(exist('leaguename','var'))
leaguename=lower(leaguename);
end
count=0;
for i=1:length(teams)
if(~isempty(strfind(lower(teams{i}.name),teamname)))
if(exist('leaguename','var'))
if(isempty(strfind(lower(teams{i}.league),leaguename)))
continue
end
end
count=count+1;
Colors{count}=max(0,min(1,teams{i}.colors));
Name{count}=teams{i}.name;
League{count}=teams{i}.league;
end
end
if(count>1)
for i = 1:count
fprintf(sprintf('<a href="matlab:colormap(genColorMap(getTeamColors(''%s'',''%s'')));">%s (%s)</a>\n',Name{i},League{i},Name{i},League{i}));
end
if nargout > 0;
warning('Matches:Multi',sprintf('Ambiguity in team name. Using %s (%s).',Name{1},League{1}));
else
return
end
elseif(count==0)
error('No team found')
end
colors = Colors{1};
name = Name{1};
League = League{1};
end