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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function p = find_equiv_posns(vsmall, vlarge)
Daniel@0 2 % FIND_EQUIV_POSNS p[i] = the place where vsmall[i] occurs in vlarge.
Daniel@0 3 % p = find_equiv_posns(vsmall, vlarge)
Daniel@0 4 % THE VECTORS ARE ASSUMED TO BE SORTED.
Daniel@0 5 %
Daniel@0 6 % e.g., vsmall=[2,8], vlarge=[2,7,8,4], p=[1,3]
Daniel@0 7 %
Daniel@0 8 % In R/S, this function is called 'match'
Daniel@0 9
Daniel@0 10 %if ~mysubset(vsmall, vlarge)
Daniel@0 11 % error('small domain must occur in large domain');
Daniel@0 12 %end
Daniel@0 13
Daniel@0 14 if isempty(vsmall) | isempty(vlarge)
Daniel@0 15 p = [];
Daniel@0 16 return;
Daniel@0 17 end
Daniel@0 18
Daniel@0 19 bitvec = sparse(1, max(vlarge));
Daniel@0 20 %bitvec = zeros(1, max(vlarge));
Daniel@0 21 bitvec(vsmall) = 1;
Daniel@0 22 p = find(bitvec(vlarge));
Daniel@0 23
Daniel@0 24 %p = find(ismember(vlarge, vsmall)); % slower