function c = count(data,k)
  % c(i,j) = number of ts for which data(t:t+1)==[i j]
  if nargin<2, k=1; end
  cmax = 27;
  % Initialize count vector
  if k==1				% MATLAB doesn't belive in 1D arraye
    c = zeros(cmax,1);
  else
    c = zeros(repmat(cmax,1,k));
  end
  for i=1:(length(data)-k+1)
    % The following is a praticularly ugly piece of code.
    % If you know of a cleaner way to do this in MATLAB, I'd be happy to
    % learn.
    a = data(i:(i+k-1));
    aa = num2cell(a);
    c(aa{:}) = c(aa{:})+1;
  end
  