function  I = extract_index( A, B )
%
%  A: source
%  B: target 
%
%  return index such that B constains in A
%

NA = length(A) ;
NB = length(B) ;

I = zeros(NB,1) ;

count = 0 ;
for j = 1:NA 
	if ( A(j) == B(1) )
		I(1) = j ;
		count = 1 ;
		break ;
	end
end

if ( 0 == count )
  str = sprintf('a contains no entry of B, B(1) = %d', B(1));
	error( str );
end

for i = 2:NB
  str = sprintf('NA = %d, NB = %d, i = %d, I(i-1) = %d', NA, NB, i, I(i-1) );
%  disp( str ) ;
	for j = I(i-1):NA 
		if ( A(j) == B(i) )
			I(i) = j ;
			count = count + 1 ;
			break ;
		end
	end
	if ( 0 == I(i) )
		break ;
	end
end

I = I(1:count) ;
