%function print_contactIndices(q)

contactR = indices_to_ranges(q.data(1).contactIndices);
contactL = indices_to_ranges(q.data(2).contactIndices);

R = [];
L = [];
for i=1:length(contactR)
	R = [R; min(contactR{i}) max(contactR{i})];
end
for i=1:length(contactL)
	L = [L; min(contactL{i}) max(contactL{i})];
end

firstRrow=1;
if R(1,1)==1
	R(1,1)=0;
	firstRrow=2;
end

firstLrow=1;
if L(1,1)==1
	L(1,1)=0;
	firstLrow=2;
end

if R(end,end)==length(q.time)
	R(end,end)=0;
end
if L(end,end)==length(q.time)
	L(end,end)=0;
end

M = [];

if R(firstRrow,1)<L(firstLrow,1)
	disp('First contact = R');
	if firstRrow==firstLrow
		M(1:2:(2*size(R,1))-1,:) = R;
		M(2:2:(2*size(L,1)),:) = L;
	elseif firstRrow+1==firstLrow
		M(1:2:(2*size(L,1))-1,:) = L;
		M(2:2:(2*size(R,1)),:) = R;
	else
		error('Unexpected case');
	end
else
	disp('First contact = L');
	if firstLrow==firstRrow
		M(1:2:(2*size(L,1))-1,:) = L;
		M(2:2:(2*size(R,1)),:) = R;
	elseif firstLrow+1==firstRrow
		M(1:2:(2*size(R,1))-1,:) = R;
		M(2:2:(2*size(L,1)),:) = L;
	else
		error('Unexpected case');
	end
end

disp(M);
