MatrixBerryCore
ismemberbyfunc.m
Go to the documentation of this file.
1 function [isThereVec,indThereVec]=ismemberbyfunc(leftVec,rightVec,fCompare)
2 import mxberry.core.throwerror;
3 if nargin<3
4  fCompare=@isequaln;
5 end
6 %%
7 if isempty(rightVec)
8  isThereVec=false(size(leftVec));
9  indThereVec=zeros(size(leftVec));
10 else
11  if ~isvector(leftVec)
12  throwerror('wrongInput','leftVec is expected to be a vector');
13  end
14  if ~isvector(rightVec)
15  throwerror('wrongInput','rightVec is expected to be a vector');
16  end
17  isCell=iscell(leftVec);
18  if iscell(rightVec)~=isCell
19  throwerror('wrongInput',...
20  ['leftVec and rightVec must be either cells or non cells ',...
21  'simultaneosly']);
22  end
23  %
24  if iscolumn(leftVec)
25  isLeftCol=true;
26  leftVec=leftVec.';
27  else
28  isLeftCol=false;
29  end
30  %
31  if isrow(rightVec)
32  rightVec=rightVec.';
33  end
34  %
35  leftVecMat=repmat(leftVec,length(rightVec),1);
36  rightVecMat=repmat(rightVec,1,length(leftVec));
37  if isCell
38  isEqualMat=cellfun(fCompare,leftVecMat,rightVecMat);
39  else
40  isEqualMat=arrayfun(fCompare,leftVecMat,rightVecMat);
41  end
42  %
43  isThereVec=any(isEqualMat,1);
44  if nargout>1
45  [indBMat,indAMat]=find(isEqualMat);
46  indAVec=indAMat(:);
47  indBVec=indBMat(:);
48  indThereVec=accumarray(indAVec,indBVec,[numel(leftVec) 1],@min,0);
49  end
50  if isLeftCol
51  isThereVec=isThereVec.';
52  else
53  indThereVec=indThereVec.';
54  end
55 end
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function repmat(in inpArray, in varargin)
function ismemberbyfunc(in leftVec, in rightVec, in fCompare)
ISMEMBERBYFUNC - ismember implementation for arrays of any type where an element comparison is perfor...