Mercurial > hg > octave-nkf
changeset 11925:e09ae0f2c767 release-3-0-x
make unique work for row vectors
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Fri, 16 Jan 2009 08:13:39 +0100 |
parents | bacb84129896 |
children | f7d4376f36d5 |
files | scripts/ChangeLog scripts/set/unique.m |
diffstat | 2 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-01-13 Daniel J Sebald <daniel.sebald@ieee.org> + + * set/unique.m: Fix for vertical array inputs. + 2008-12-18 Daniel J Sebald <daniel.sebald@ieee.org> * set/unique.m: Only check for options if nargin > 1.
--- a/scripts/set/unique.m +++ b/scripts/set/unique.m @@ -74,8 +74,10 @@ if (optrows) n = size (x, 1); + dim = 1; else n = numel (x); + dim = (size (x, 1) == 1) + 1; endif y = x; @@ -108,7 +110,11 @@ if (nargout >= 3) j = i; - j(i) = cumsum ([1, !match]); + if (dim == 1) + j(i) = cumsum ([1; !match]); + else + j(i) = cumsum ([1, !match]); + end endif if (optfirst) @@ -128,7 +134,7 @@ %!assert(unique([1;2]),[1;2]) %!assert(unique([1,NaN,Inf,NaN,Inf]),[1,Inf,NaN,NaN]) %!assert(unique({'Foo','Bar','Foo'}),{'Bar','Foo'}) -%!assert(unique({'Foo','Bar','FooBar'}),{'Bar','Foo','FooBar'}) +%!assert(unique({'Foo','Bar','FooBar'}'),{'Bar','Foo','FooBar'}') %!test %! [a,i,j] = unique([1,1,2,3,3,3,4]); @@ -137,7 +143,20 @@ %! assert(j,[1,1,2,3,3,3,4]) %! %!test -%! [a,i,j] = unique([1,1,2,3,3,3,4],'first'); -%! assert(a,[1,2,3,4]) -%! assert(i,[1,3,4,7]) -%! assert(j,[1,1,2,3,3,3,4]) +%! [a,i,j] = unique([1,1,2,3,3,3,4]','first'); +%! assert(a,[1,2,3,4]') +%! assert(i,[1,3,4,7]') +%! assert(j,[1,1,2,3,3,3,4]') +%! +%!test +%! [a,i,j] = unique({'z'; 'z'; 'z'}); +%! assert(a,{'z'}) +%! assert(i,[3]') +%! assert(j,[1,1,1]') +%! +%!test +%! A=[1,2,3;1,2,3]; +%! [a,i,j] = unique(A,'rows'); +%! assert(a,[1,2,3]) +%! assert(A(i,:),a) +%! assert(a(j,:),A)