% function I = findrows(A, B) % % A function that given two string arrays A and B, % returns the list of row indices in A for which % there is a match in B. It assumes that both A and % B are sorted alphabetically on entry, and that B % is smaller than A. Furthermore, it assumes there % is a match in A for every entry in B. % function I = findrows(A, B) [mA,nA] = size(A); [mB,nB] = size(B); I = []; Aptr = 1; Bptr = 1; for k = 1:mB t = deblank(B(k,:)); for j = Aptr:mA if (strcmp(deblank(A(j,:)),t)) break; end end Aptr = j; I = [I; j]; end