NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/matutil/distinct.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function b = distinct(a,flag)
2 %DISTINCT Set unique.
3 %   DISTINCT(A) for the array A returns the same values as in A but
4 %   with no repetitions. This is a scaled down version of the
5 %   Matlab program UNIQUE. If you do not want sorted rows and other
6 %   unnecessary stuff, welcome!
7 %
8 %   DISTINCT(A,'rows') for the matrix A returns the unique rows of A.
9 %
10  
11 if nargin==1 | isempty(flag),
12   % Convert matrices and rectangular empties into columns
13   if length(a) ~= prod(size(a)) | (isempty(a) & any(size(a)))
14      a = a(:);
15   end
16   % d indicates the location of matching entries
17   b=a;
18   d = b((1:end-1)')==b((2:end)');
19   b(find(d)) = [];
20   if nargout==2, % Create position mapping vector
21     pos = zeros(size(a));
22   end
23 else
24   if ~isstr(flag) | ~strcmp(flag,'rows'), error('Unknown flag.'); end
25   b = a;
26   [m,n] = size(a);
27   if m > 1 & n ~= 0
28     % d indicates the location of matching entries
29     d = b(1:end-1,:)==b(2:end,:);
30   else
31     d = zeros(m-1,n);
32   end
33   d = all(d,2);
34   b(find(d),:) = [];
35   if nargout==3, % Create position mapping vector
36     pos(ndx) = cumsum([1;~d]);
37     pos = pos';
38   end
39 end
Note: See TracBrowser for help on using the browser.