wolffd@0: function p = find_equiv_posns(vsmall, vlarge) wolffd@0: % FIND_EQUIV_POSNS p[i] = the place where vsmall[i] occurs in vlarge. wolffd@0: % p = find_equiv_posns(vsmall, vlarge) wolffd@0: % THE VECTORS ARE ASSUMED TO BE SORTED. wolffd@0: % wolffd@0: % e.g., vsmall=[2,8], vlarge=[2,7,8,4], p=[1,3] wolffd@0: % wolffd@0: % In R/S, this function is called 'match' wolffd@0: wolffd@0: %if ~mysubset(vsmall, vlarge) wolffd@0: % error('small domain must occur in large domain'); wolffd@0: %end wolffd@0: wolffd@0: if isempty(vsmall) | isempty(vlarge) wolffd@0: p = []; wolffd@0: return; wolffd@0: end wolffd@0: wolffd@0: bitvec = sparse(1, max(vlarge)); wolffd@0: %bitvec = zeros(1, max(vlarge)); wolffd@0: bitvec(vsmall) = 1; wolffd@0: p = find(bitvec(vlarge)); wolffd@0: wolffd@0: %p = find(ismember(vlarge, vsmall)); % slower