function b = defbands(clusters,K)
% b = defbands(clusters,K)
% Assumes non-zero centers
% Merge any clusters which are one row apart and centers within K
[m n] = size(clusters);
last = 1;
b(1,1) = clusters(1,1); b(1,2) = clusters(1,2); b(1,3) = clusters(1,3);
b(1,4) = clusters(1,4); b(1,5) = clusters(1,5); b(1,6) = clusters(1,6);
b(1,7) = clusters(1,7);
for i1 = 2:m
  center1 = clusters(i1,4);
  row1 = clusters(i1,1);
  merged = 0;
  i2 = last+1;
  while (i2>1) & (merged==0)
    i2 = i2-1;
    center2 = b(i2,4);
    row2 = b(i2,1);
    if abs(row1-row2)<2 & abs(center1-center2)<K
      b(i2,4) = (center1+center2)/2;
      merged = 1;
    end
  end
  if merged==0
    last = last+1;
    b(last,1) = clusters(i1,1); b(last,2) = clusters(i1,2);
    b(last,3) = clusters(i1,3); b(last,6) = clusters(i1,6);
    b(last,4) = clusters(i1,4); b(last,5) = clusters(i1,5);
    b(last,7) = clusters(i1,7);
  end
end
