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

plotCountryMedals(medals, teams, countries)
% FILE:    plotCountryMedals.m
% PURPOSE: how many medals were awarded over all time to named countries?
% REQUIRES:
%   run allSummers
% EXAMPLE:
%   plotCountryMedals(medals, teamobj, {'Soviet Union', 'Russia'})

function plotCountryMedals(medals, teams, countries)
  n=numel(countries);
  if n <= 5                  % which it should be
    cm(1,:) = [1,0,0];
    cm(2,:) = [0,1,0];
    cm(3,:) = [0,0,1];
    cm(4,:) = [1,0,1];
    cm(5,:) = [.5,.5,.5];
  else
    cm = jet(n);
  end

  ol = size(medals,2);       % olympiads
  x=1896:4:(1896+(ol-1)*4);  % x axis
  total = getTotalMedals(medals);
  close
  hold on
  total(total==0)=-inf;    % 0 means no data, remove point
  plot(x,total, '.-k');
  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.total]);
      meds(meds==0)=-inf;    % 0 means no data, remove point
    end
    plot(x,meds, '.-', 'color', cm(c,:));
  end

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

Contact us at files@mathworks.com