Mercurial > octave-nkf
annotate scripts/set/unique.m @ 10373:1f11fabfa349
improve performance of unique for sparse arrays
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 28 Feb 2010 12:32:16 -0500 |
parents | 634e182d34e4 |
children | be55736a0783 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2008, 2009 Jaroslav Hajek |
7017 | 2 ## Copyright (C) 2000, 2001, 2005, 2006, 2007 Paul Kienzle |
7016 | 3 ## |
4 ## This file is part of Octave. | |
5165 | 5 ## |
7016 | 6 ## Octave is free software; you can redistribute it and/or modify it |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
5165 | 10 ## |
7016 | 11 ## Octave is distributed in the hope that it will be useful, but |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
5165 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5165 | 19 |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {} unique (@var{x}) | |
8887 | 22 ## @deftypefnx {Function File} {} unique (@var{x}, "rows") |
23 ## @deftypefnx {Function File} {} unique (@dots{}, "first") | |
24 ## @deftypefnx {Function File} {} unique (@dots{}, "last") | |
25 ## @deftypefnx {Function File} {[@var{y}, @var{i}, @var{j}] =} unique (@dots{}) | |
5165 | 26 ## Return the unique elements of @var{x}, sorted in ascending order. |
27 ## If @var{x} is a row vector, return a row vector, but if @var{x} | |
28 ## is a column vector or a matrix return a column vector. | |
10088
5edee330d4cb
better argument checking and handling in set functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
29 ## @var{x} can be a cell array of strings. |
5165 | 30 ## |
8887 | 31 ## If the optional argument @code{"rows"} is supplied, return the unique |
32 ## rows of @var{x}, sorted in ascending order. | |
5165 | 33 ## |
8887 | 34 ## If requested, return index vectors @var{i} and @var{j} such that |
35 ## @code{x(i)==y} and @code{y(j)==x}. | |
36 ## | |
37 ## Additionally, one of @code{"first"} or @code{"last"} may be given as | |
38 ## an argument. If @code{"last"} is specified, return the highest | |
39 ## possible indices in @var{i}, otherwise, if @code{"first"} is | |
40 ## specified, return the lowest. The default is @code{"last"}. | |
5642 | 41 ## @seealso{union, intersect, setdiff, setxor, ismember} |
5165 | 42 ## @end deftypefn |
43 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
44 function [y, i, j] = unique (x, varargin) |
5165 | 45 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
46 if (nargin < 1) |
6046 | 47 print_usage (); |
5165 | 48 endif |
49 | |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
50 if (nargin > 1) |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
51 |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
52 ## parse options |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
53 if (iscellstr (varargin)) |
8413
b8de157b4948
ChangeLog entry and style fixes for last two patches
Jaroslav Hajek <highegg@gmail.com>
parents:
8412
diff
changeset
|
54 varargin = unique (varargin); |
8887 | 55 optfirst = strmatch ("first", varargin) > 0; |
56 optlast = strmatch ("last", varargin) > 0; | |
10372
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
57 optrows = strmatch ("rows", varargin) > 0; |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
58 if (optfirst && optlast) |
8664 | 59 error ("unique: cannot specify both \"last\" and \"first\""); |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
60 elseif (optfirst + optlast + optrows != nargin-1) |
8664 | 61 error ("unique: invalid option"); |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
62 endif |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
63 else |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
64 error ("unique: options must be strings"); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
65 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
66 |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
67 if (optrows && iscell (x)) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
68 warning ("unique: 'rows' is ignored for cell arrays"); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
69 optrows = false; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
70 endif |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
71 |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
72 else |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
73 optfirst = 0; |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
74 optrows = 0; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
75 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
76 |
10373
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
77 ## FIXME -- the operations |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
78 ## |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
79 ## match = (y(1:n-1) == y(2:n)); |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
80 ## y(idx) = []; |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
81 ## |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
82 ## are very slow on sparse matrices. Until they are fixed to be as |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
83 ## fast as for full matrices, operate on the nonzero elements of the |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
84 ## sparse array as long as we are not operating on rows. |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
85 |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
86 ## FIXME -- unique is called when PKG_ADD files are parsed, but |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
87 ## issparse is not yet available because it is coming from a .oct |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
88 ## file?!? |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
89 |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
90 if (exist ("issparse")) |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
91 if (issparse (x) && ! optrows && nargout <= 1) |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
92 y = unique ([0; (full (nonzeros (x)))], varargin{:}); |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
93 return; |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
94 endif |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
95 endif |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
96 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
97 if (optrows) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
98 n = size (x, 1); |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
99 dim = 1; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
100 else |
6609 | 101 n = numel (x); |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
102 dim = (size (x, 1) == 1) + 1; |
5165 | 103 endif |
104 | |
5168 | 105 y = x; |
5165 | 106 if (n < 1) |
10372
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
107 if (! optrows && isempty (x) && any (size (x))) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
108 if (iscell (y)) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
109 y = cell (0, 1); |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
110 else |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
111 y = zeros (0, 1, class (y)); |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
112 endif |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
113 endif |
5165 | 114 i = j = []; |
5168 | 115 return; |
5165 | 116 elseif (n < 2) |
117 i = j = 1; | |
5168 | 118 return; |
5165 | 119 endif |
120 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
121 if (optrows) |
5168 | 122 [y, i] = sortrows (y); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
123 match = all (y(1:n-1,:) == y(2:n,:), 2); |
5165 | 124 idx = find (match); |
5168 | 125 y(idx,:) = []; |
5165 | 126 else |
5168 | 127 if (size (y, 1) != 1) |
128 y = y(:); | |
129 endif | |
130 [y, i] = sort (y); | |
5205 | 131 if (iscell (y)) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
132 match = strcmp (y(1:n-1), y(2:n)); |
5205 | 133 else |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
134 match = (y(1:n-1) == y(2:n)); |
5205 | 135 endif |
5165 | 136 idx = find (match); |
5168 | 137 y(idx) = []; |
5165 | 138 endif |
139 | |
140 if (nargout >= 3) | |
141 j = i; | |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
142 if (dim == 1) |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
143 j(i) = cumsum ([1; !match]); |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
144 else |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
145 j(i) = cumsum ([1, !match]); |
8610
85c9906abfd1
use endif and endfor instead of end
John W. Eaton <jwe@octave.org>
parents:
8502
diff
changeset
|
146 endif |
5165 | 147 endif |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
148 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
149 if (optfirst) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
150 i(idx+1) = []; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
151 else |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
152 i(idx) = []; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
153 endif |
5165 | 154 |
155 endfunction | |
156 | |
157 %!assert(unique([1 1 2; 1 2 1; 1 1 2]),[1;2]) | |
158 %!assert(unique([1 1 2; 1 0 1; 1 1 2],'rows'),[1 0 1; 1 1 2]) | |
159 %!assert(unique([]),[]) | |
160 %!assert(unique([1]),[1]) | |
161 %!assert(unique([1 2]),[1 2]) | |
162 %!assert(unique([1;2]),[1;2]) | |
163 %!assert(unique([1,NaN,Inf,NaN,Inf]),[1,Inf,NaN,NaN]) | |
5205 | 164 %!assert(unique({'Foo','Bar','Foo'}),{'Bar','Foo'}) |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
165 %!assert(unique({'Foo','Bar','FooBar'}'),{'Bar','Foo','FooBar'}') |
10372
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
166 %!assert(unique(zeros(1,0)), zeros(0,1)) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
167 %!assert(unique(zeros(1,0), 'rows'), zeros(1,0)) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
168 %!assert(unique(cell(1,0)), cell(0,1)) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
169 %!assert(unique({}), {}) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
170 %!assert(unique([1,2,2,3,2,4], 'rows'), [1,2,2,3,2,4]) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
171 %!assert(unique([1,2,2,3,2,4]), [1,2,3,4]) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
172 %!assert(unique([1,2,2,3,2,4]', 'rows'), [1,2,3,4]') |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
173 %!assert(unique(single([1,2,2,3,2,4]), 'rows'), single([1,2,2,3,2,4])) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
174 %!assert(unique(single([1,2,2,3,2,4])), single([1,2,3,4])) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
175 %!assert(unique(single([1,2,2,3,2,4]'), 'rows'), single([1,2,3,4]')) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
176 %!assert(unique(uint8([1,2,2,3,2,4]), 'rows'), uint8([1,2,2,3,2,4])) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
177 %!assert(unique(uint8([1,2,2,3,2,4])), uint8([1,2,3,4])) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
178 %!assert(unique(uint8([1,2,2,3,2,4]'), 'rows'), uint8([1,2,3,4]')) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
179 %!test |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
180 %! [a,i,j] = unique([1,1,2,3,3,3,4]); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
181 %! assert(a,[1,2,3,4]) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
182 %! assert(i,[2,3,6,7]) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
183 %! assert(j,[1,1,2,3,3,3,4]) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
184 %! |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
185 %!test |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
186 %! [a,i,j] = unique([1,1,2,3,3,3,4]','first'); |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
187 %! assert(a,[1,2,3,4]') |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
188 %! assert(i,[1,3,4,7]') |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
189 %! assert(j,[1,1,2,3,3,3,4]') |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
190 %! |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
191 %!test |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
192 %! [a,i,j] = unique({'z'; 'z'; 'z'}); |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
193 %! assert(a,{'z'}) |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
194 %! assert(i,[3]') |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
195 %! assert(j,[1,1,1]') |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
196 %! |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
197 %!test |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
198 %! A=[1,2,3;1,2,3]; |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
199 %! [a,i,j] = unique(A,'rows'); |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
200 %! assert(a,[1,2,3]) |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
201 %! assert(A(i,:),a) |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
202 %! assert(a(j,:),A) |