image thumbnail
from Summer Olympic Medals 1896-present by Bill McKeeman
Ways of looking at the record of summer olympic medals

plotCountryGolds(medals, teams, countries)
% FILE:    plotCountryGolds.m
% PURPOSE: how many gold medals were awarded over all time?
% REQUIRES:
%   allSummers() % to get medals(teams,olympiads)  
%   teamobj = teamNames();  
% EXAMPLE:
%   plotCountryGolds(medals, teamobj, {'Soviet Union', 'Russia'})

function plotCountryGolds(medals, teams, countries)
  close
  n=numel(countries);
  % set up graph colors
  if n <= 5                   % which it should be
    cm(1,:) = [1,0,0];
    cm(2,:) = [1,0,1];
    cm(3,:) = [0,0,1];
    cm(4,:) = [0,1,0];
    cm(5,:) = [.5,.5,.5];
  else
    cm = jet(n);
  end
  hold on

  ol = size(medals,2);
  x=1896:4:(1896+(ol-1)*4);  % x axis
  for c=1:n
    cno = teams.enter(countries{c});
    meds = zeros(1,ol);
    for i = 1:ol
      rec = medals(cno,i);
      meds(i) = sum([rec.gold]);
      meds(meds==0)=-inf;    % 0 means no data, remove point
    end
    plot(x,meds, 'o:', 'color', cm(c,:));
  end

  legend(countries{:}, 'location', 'southwestoutside');
  title('Total gold medals awarded in each Summer Olympics');
  hold off
end

Contact us at files@mathworks.com