annotate toolboxes/FullBNT-1.0.7/KPMtools/find_equiv_posns.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function p = find_equiv_posns(vsmall, vlarge)
wolffd@0 2 % FIND_EQUIV_POSNS p[i] = the place where vsmall[i] occurs in vlarge.
wolffd@0 3 % p = find_equiv_posns(vsmall, vlarge)
wolffd@0 4 % THE VECTORS ARE ASSUMED TO BE SORTED.
wolffd@0 5 %
wolffd@0 6 % e.g., vsmall=[2,8], vlarge=[2,7,8,4], p=[1,3]
wolffd@0 7 %
wolffd@0 8 % In R/S, this function is called 'match'
wolffd@0 9
wolffd@0 10 %if ~mysubset(vsmall, vlarge)
wolffd@0 11 % error('small domain must occur in large domain');
wolffd@0 12 %end
wolffd@0 13
wolffd@0 14 if isempty(vsmall) | isempty(vlarge)
wolffd@0 15 p = [];
wolffd@0 16 return;
wolffd@0 17 end
wolffd@0 18
wolffd@0 19 bitvec = sparse(1, max(vlarge));
wolffd@0 20 %bitvec = zeros(1, max(vlarge));
wolffd@0 21 bitvec(vsmall) = 1;
wolffd@0 22 p = find(bitvec(vlarge));
wolffd@0 23
wolffd@0 24 %p = find(ismember(vlarge, vsmall)); % slower