MatrixBerryCore
ismembersortableobj.m
Go to the documentation of this file.
1 function [isThereVec,indThereVec] = ismembersortableobj(firstVec,secVec)
2 import mxberry.core.uniquesortableobj;
3 %
4 if isscalar(firstVec) || isscalar(secVec)
5  unitedVec = [firstVec(:);secVec(:)];
6  nFirstElems = numel(firstVec);
7  isThereVec = unitedVec(1:nFirstElems)==unitedVec(1+nFirstElems:end);
8  if any(isThereVec)
9  if isscalar(secVec)
10  indThereVec = double(isThereVec);
11  else
12  indThereVec = find(isThereVec);
13  indThereVec = indThereVec(1);
14  isThereVec = any(isThereVec);
15  end
16  else
17  isThereVec = false(size(firstVec));
18  indThereVec = zeros(size(firstVec));
19  end
20 else
21  [unqFirstVec,~,indFirstLeft2RightVec] = uniquesortableobj(firstVec(:));
22  if nargout <= 1
23  unqSecVec = uniquesortableobj(secVec(:));
24  else
25  [unqSecVec,indSecRight2LeftVec] = uniquesortableobj(secVec(:));
26  end
27  %
28  [unionSortedVec,indUnionSortedVec] = sort([unqFirstVec;unqSecVec]);
29  %
30  isSortedUnionNeighborEqVec = unionSortedVec(1:end-1)==...
31  unionSortedVec(2:end);
32  indSortedUnionNeighborEqVec = indUnionSortedVec(...
33  isSortedUnionNeighborEqVec);
34  %
35  if nargout <= 1
36  isThereVec = ismember(indFirstLeft2RightVec,...
37  indSortedUnionNeighborEqVec);
38  else
39  nFirstUnqElems = size(unqFirstVec,1);
40  isSortedUnionNeighborEqVec = find(isSortedUnionNeighborEqVec);
41  [isThereVec,indThereVec] = ismember(indFirstLeft2RightVec,...
42  indSortedUnionNeighborEqVec);
43  isFirstAmonthEqSortedUnionNeighborsVec =...
44  isSortedUnionNeighborEqVec(indThereVec(isThereVec));
45  indWhereFirstAmongEqNeighborsVec =...
46  indSecRight2LeftVec(indUnionSortedVec(...
47  isFirstAmonthEqSortedUnionNeighborsVec+1)-nFirstUnqElems);
48  indThereVec(isThereVec) = indWhereFirstAmongEqNeighborsVec;
49  end
50 end
51 isThereVec = reshape(isThereVec,size(firstVec));
52 if nargout > 1
53  indThereVec = reshape(indThereVec,size(firstVec));
54 end
function uniquesortableobj(in inpVec)
UNIQUE implementation strictly for sortable entities i.e. for those that have 1) full order defined b...
function ismembersortableobj(in firstVec, in secVec)
ISMEMBER implementation strictly for sortable entities i.e. for those that have 1) full order defined...
function ismember(in leftVec, in rightVec, in varargin)
ISMEMBER - ismember implementation for arrays of any type.