function [ictoMatrix, FP, limb] = build_delaware_ictoMatrix(contactRanges, firstICLimb, firstICFP, plotq)

n = size(contactRanges,1)-3;

ictoMatrix = zeros(n,5);

FP = { firstICFP };
limb = { firstICLimb };
for i=2:n
	FP = {FP{:} (3-FP{end})};
	switch limb{end}
		case 'L'
			otherlimb = 'R';
		case 'R'
			otherlimb = 'L';
	end
	limb = {limb{:} otherlimb};
end

for i=1:n
	ictoMatrix(i,:) = [contactRanges(i+1,1) contactRanges(i,2) contactRanges(i+2,1) contactRanges(i+1,2) contactRanges(i+3,1)];
end

% Plot
if nargin >= 4
	figure
	hold on
	for i=1:2:n
		I=ictoMatrix(i,1):ictoMatrix(i,4);
		plot(I, plotq.data(FP{i}).filteredF(I,2));
	end
	title(sprintf('LIMB = %s', limb{1}));
	hold off
	figure
	hold on
	for i=2:2:n
		I=ictoMatrix(i,1):ictoMatrix(i,4);
		plot(I, plotq.data(FP{i}).filteredF(I,2));
	end
	title(sprintf('LIMB = %s', limb{2}));
	hold off
end
