MatrixBerryCore
uniquesortableobj.m
Go to the documentation of this file.
1 function [unqVec,indRight2LeftVec,indLeft2RightVec]=uniquesortableobj(inpVec)
2 isRowInput = isrow(inpVec);
3 %
4 inpVec = inpVec(:);
5 nInpElems = numel(inpVec);
6 %
7 if nargout > 1
8  [sortedInpVec,indSortedVec] = sort(inpVec);
9 else
10  sortedInpVec = sort(inpVec);
11 end
12 %
13 isEqualSortedNeighborVec=sortedInpVec(1:nInpElems-1)~=...
14  sortedInpVec(2:nInpElems);
15 %
16 if (nInpElems ~= 0)
17  isEqualSortedNeighborVec = [true; isEqualSortedNeighborVec];
18 else
19  isEqualSortedNeighborVec = zeros(0,1);
20 end
21 %
22 unqVec = sortedInpVec(isEqualSortedNeighborVec);
23 if nargout > 1
24  indRight2LeftVec = indSortedVec(isEqualSortedNeighborVec);
25 end
26 %
27 if nargout == 3
28  isEqualSortedNeighborVec = full(isEqualSortedNeighborVec);
29  if nInpElems == 0
30  indLeft2RightVec = zeros(0,1);
31  else
32  indLeft2RightVec = cumsum(isEqualSortedNeighborVec);
33  indLeft2RightVec(indSortedVec) = indLeft2RightVec;
34  end
35 end
36 %
37 if isRowInput
38  unqVec = unqVec.';
39 end
40 
function uniquesortableobj(in inpVec)
UNIQUE implementation strictly for sortable entities i.e. for those that have 1) full order defined b...
function isrow(in inpArray)