about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/find_equiv_posns.m
blob: cc2b8b1b256cea684684cc21cc7c9c8b50c154b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function p = find_equiv_posns(vsmall, vlarge)
% FIND_EQUIV_POSNS p[i] = the place where vsmall[i] occurs in vlarge.
% p = find_equiv_posns(vsmall, vlarge)
% THE VECTORS ARE ASSUMED TO BE SORTED.
%
% e.g., vsmall=[2,8], vlarge=[2,7,8,4], p=[1,3]
%
% In R/S, this function is called 'match'
 
%if ~mysubset(vsmall, vlarge)
%  error('small domain must occur in large domain');
%end

if isempty(vsmall) || isempty(vlarge)
  p = [];
  return;
end
  
bitvec = sparse(1, max(vlarge)); 
%bitvec = zeros(1, max(vlarge));
bitvec(vsmall) = 1;
p = find(bitvec(vlarge));

%p = find(ismember(vlarge, vsmall)); % slower