Mercurial > octave-nkf
comparison scripts/set/unique.m @ 5205:59592dcbb5d8
[project @ 2005-03-15 16:04:56 by jwe]
author | jwe |
---|---|
date | Tue, 15 Mar 2005 16:04:57 +0000 |
parents | 912058eb8360 |
children | 4c8a2e4e0717 |
comparison
equal
deleted
inserted
replaced
5204:2a44a667da02 | 5205:59592dcbb5d8 |
---|---|
58 y = toascii (y); | 58 y = toascii (y); |
59 endif | 59 endif |
60 | 60 |
61 if (nargin == 2) | 61 if (nargin == 2) |
62 [y, i] = sortrows (y); | 62 [y, i] = sortrows (y); |
63 match = all ((y(1:n-1,:) == y(2:n,:))'); | 63 if (iscell (y)) |
64 match = cellfun ("size", y(1:n-1,:), 1) == cellfun ("size", y(2:n,:), 1); | |
65 idx = find (match); | |
66 match(idx) = all (char (y(idx)) == char (y(idx+1)), 2); | |
67 match = all (match'); | |
68 else | |
69 match = all ([y(1:n-1,:) == y(2:n,:)]'); | |
70 endif | |
64 idx = find (match); | 71 idx = find (match); |
65 y(idx,:) = []; | 72 y(idx,:) = []; |
66 else | 73 else |
67 if (size (y, 1) != 1) | 74 if (size (y, 1) != 1) |
68 y = y(:); | 75 y = y(:); |
69 endif | 76 endif |
70 [y, i] = sort (y); | 77 [y, i] = sort (y); |
71 match = y(1:n-1) == y(2:n); | 78 if (iscell (y)) |
79 match = cellfun ("length", y(1:n-1)) == cellfun ("length", y(2:n)); | |
80 idx = find(match); | |
81 match(idx) = all (char (y(idx)) == char (y(idx+1)), 2); | |
82 else | |
83 match = [y(1:n-1) == y(2:n)]; | |
84 endif | |
72 idx = find (match); | 85 idx = find (match); |
73 y(idx) = []; | 86 y(idx) = []; |
74 endif | 87 endif |
75 | 88 |
76 ## I don't know why anyone would need reverse indices, but it | 89 ## I don't know why anyone would need reverse indices, but it |
92 %!assert(unique([]),[]) | 105 %!assert(unique([]),[]) |
93 %!assert(unique([1]),[1]) | 106 %!assert(unique([1]),[1]) |
94 %!assert(unique([1 2]),[1 2]) | 107 %!assert(unique([1 2]),[1 2]) |
95 %!assert(unique([1;2]),[1;2]) | 108 %!assert(unique([1;2]),[1;2]) |
96 %!assert(unique([1,NaN,Inf,NaN,Inf]),[1,Inf,NaN,NaN]) | 109 %!assert(unique([1,NaN,Inf,NaN,Inf]),[1,Inf,NaN,NaN]) |
110 %!assert(unique({'Foo','Bar','Foo'}),{'Bar','Foo'}) | |
111 %!assert(unique({'Foo','Bar','FooBar'}),{'Bar','Foo','FooBar'}) |